[Tutor] Malloc, bitwise operations and other nasties

Art Siegel ajs@ix.netcom.com
Tue, 9 Mar 1999 13:45:54 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_000A_01BE6A33.273C6B60
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable


I am retransmitting the following. I apologize if duplicated.


The following is a code snippet from OpenGL demo code I am trying to =
port to Python.=20
/* Create a single component texture map */=20
GLfloat *=20
make_texture(int maxs, int maxt)=20
{=20
int s, t;=20
static GLfloat *texture;=20
texture =3D (GLfloat *) malloc(maxs * maxt * sizeof(GLfloat));=20
for (t =3D 0; t < maxt; t++) {=20
for (s =3D 0; s < maxs; s++) {=20
texture[s + maxs * t] =3D ((s >> 4) & 0x1) ^ ((t >> 4) & 0x1);=20
}=20
}=20
return texture;=20
}
The code creates a checkerboard texture, which gets mapped to an object.
Between the malloc call (something to do with memory, I know) and the =
bitwise operators, I am lost.
I certainly can't see how this becomes a texturemap.
If I saw the code in Pythonese, I couldl probably begin to understand =
it.=20
Any help is appreciated.



------=_NextPart_000_000A_01BE6A33.273C6B60
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>I am retransmitting the following. I =
apologize=20
if duplicated.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>The following is a code snippet from OpenGL demo code I am trying =
to port=20
to Python. </DIV>
<DIV>/* Create a single component texture map */ </DIV>
<DIV>GLfloat * </DIV>
<DIV>make_texture(int maxs, int maxt) </DIV>
<DIV>{ </DIV>
<DIV>int s, t; </DIV>
<DIV>static GLfloat *texture; </DIV>
<DIV>texture =3D (GLfloat *) malloc(maxs * maxt * sizeof(GLfloat)); =
</DIV>
<DIV>for (t =3D 0; t &lt; maxt; t++) { </DIV>
<DIV>for (s =3D 0; s &lt; maxs; s++) { </DIV>
<DIV>texture[s + maxs * t] =3D ((s &gt;&gt; 4) &amp; 0x1) ^ ((t &gt;&gt; =
4) &amp;=20
0x1); </DIV>
<DIV>} </DIV>
<DIV>} </DIV>
<DIV>return texture; </DIV>
<DIV>}</DIV>
<DIV>The code creates a checkerboard texture, which gets mapped to an=20
object.</DIV>
<DIV>Between the malloc call (something to do with memory, I know) and =
the=20
bitwise operators, I am lost.</DIV>
<DIV>I certainly can't see how this becomes a texturemap.</DIV>
<DIV>If I saw the code in Pythonese, I couldl probably begin to =
understand it.=20
</DIV>
<DIV>Any help is appreciated.</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV></DIV></BODY></HTML>

------=_NextPart_000_000A_01BE6A33.273C6B60--