#### Archived

This topic is now archived and is closed to further replies.

# Please explain this code to me

This topic is 6045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

unsigned char g_letterA[] = { 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xDF, 0xFB, 0x7F, 0xFE, 0x60, 0x06, 0x30, 0x0C, 0x18, 0x18, 0x18, 0x18, 0x0C, 0x30, 0x0C, 0x30, 0x07, 0xE0, 0x07, 0xE0 }; .... ... void Display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glColor3f(1.0f, 1.0f, 1.0f); glRasterPos2f(50, 50); glBitmap(16, 16, 0.0f, 0.0f, 0.0f, 0.0f, g_letterA); glutSwapBuffers(); return; } ok, I understand that this will draw the letter ''A'' to the screen. I don''t understand what all the 0xC0 things are and how they translate into each bit being a 1 or 0. Could someone explain this to me? The other thing I don''t understand is what the glPixelStorei() function does.

##### Share on other sites
They are simply hexadecimal numbers, which you can see by the "0x" prefix. Each hexadecimal digit (which is 0..9 or A..F) is called a nibble and represents four bits.

0 hex = 0000 binary = 0 decimal1 = 0001 = 12 = 0010 = 23 = 0011 = 34 = 0100 = 45 = 0101 = 56 = 0110 = 67 = 0111 = 78 = 1000 = 89 = 1001 = 9A = 1010 = 10B = 1011 = 11C = 1100 = 12D = 1101 = 13E = 1110 = 14F = 1111 = 15

One of the values you find is 0xFB. This translates to binary as 11111011, which in decimal is 15 * 16 + 11 = 251

So there you have your ones and zeroes. This array is a sequence of 30 bytes, each storing 8 bits, so that''s 240 pixels. If you use the table I gave you above and convert it to a pattern of ones and zeroes, you''ll get the following:

11000000 0000001111000000 0000001111000000 0000001111000000 0000001111000000 0000001111011111 1111101101111111 1111111001100000 0000011000110000 0000110000011000 0001100000011000 0001100000001100 0011000000001100 0011000000000111 1110000000000111 11100000

As you can see, that''s an upside-down A. Do a Google search for some more info on binary arithmetic and you should find enough to give you a more in-depth explanation.
The glPixelStorei call tells OpenGL what kind of byte-alignment to use, which is a bit more complicated than I want to explain right now. Just look up the function in MSDN. They explain it nicely.

##### Share on other sites
Thank you. You explained it quite nicely. I will check out MSDN also.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631781
• Total Posts
3002315
×