PDA

View Full Version : Drawing with glColor3ui, Blank Screen



image28
01-26-2009, 07:19 PM
Hi I'm having trouble getting pixels to draw in 2D with glColor3ui, seems to work with glColor3f though. The screen
just comes up blank

Init code


if ( (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) == -1 ) )
{
printf("Could not initialize SDL: %s.\n", SDL_GetError());
exit(-1);
}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);

screen.image = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL|SDL_FULLSCREEN);

glClearColor(0.0,0.0,0.0,0.0);
SDL_GL_SwapBuffers();

glViewport(0,0,640,480);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluOrtho2D(0,640,480,0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();


Drawing Code


colour.G=0;

for(d=0;d<200;d++)
{
colour.G++;
glBegin(GL_POINTS);
glColor3ui(colour.R,colour.G,colour.B);
glVertex2i(640/2+d,480/2);
glEnd();
}

ZbuffeR
01-27-2009, 01:47 AM
ui means unsigned int, color ranges from 0 to 4.2 billion.
f means float, color range is normalized from 0.0f to 1.0f.

working with ub is often more realistic, as it matches the 16.7 million colors of typical display. Color range is 0 to 255 in this case.

_NK47
01-27-2009, 03:54 AM
means 1.0f is converted to unsigned int 1 instead of 255 which is like the closest step to complete black (0).