I am writing a program in windows using c++, opengl 2.1and SDL, and I have some problems with vertex colors.
I use glColor3fto set the color for each set of vertices, but it doesn't seem to work. I get every vertex red, no matter what color I choose. I checked the values passed on glColor3fand they really are not 1.f, 0.f, 0.f ...
Has anyone encountered such a problem or knows what might cause it? Maybe I won’t go into any library? Or do you think this might be a problem with the SDL initialization code (it shouldn't be, since I used it before it was correct)?
EDIT4: Solved .. This is really a gpu problem, I got the drivers from the manufacturer and now it works fine ... go figure
EDIT: I also do not use any lighting, texture or anything like that. Graphically, I just set the window and talk about how to draw some vertices and colors.
EDIT2: Of course, but I very much doubt that there is a problem:
int GLmain::redraw(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_LINE_STRIP);
for(int i=0; i<s->divs.size(); i++){
vec3 v = s->divs.at(i).getPosition();
vec3 c = s->divs.at(i).getColor();
glColor3f(c.get(0),c.get(1),c.get(2));
glVertex3f(v.get(0),v.get(1),v.get(2));
}
glEnd();
return TRUE;
}
As you can see, pretty standard stuff .. c contains values between 0.0-1.0. I just tried to start some other work that I did with OpenGL, and everything also appears in red (this was not earlier), so I assume that this has something to do with the libraries I use:
opengl32.lib
sdl.lib
sdlmain.lib
glu32.lib
SDL - version 1.2.14. Also, could this be a problem with my gpu? Everything else appears with the usual colors, but .. web browser, video, games, etc.
EDIT3: SDL initialization code:
int done = 0;
int w = 800;
int h = 600;
GLenum gl_error;
char* sdl_error;
SDL_Event event;
Init_OpenGL(argc, argv, w, h);
SDL_WM_SetCaption( "MySlinky", "" );
void Init_OpenGL(int argc, char* argv[], int w, int h)
{
int rgb_size[3];
int bpp = 0;
Uint32 video_flags = SDL_OPENGL;
if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
exit( 1 );
}
if ( bpp == 0 ) {
if ( SDL_GetVideoInfo()->vfmt->BitsPerPixel <= 8 ) {
bpp = 8;
} else {
bpp = 16;
}
}
switch (bpp) {
case 8:
rgb_size[0] = 3;
rgb_size[1] = 3;
rgb_size[2] = 2;
break;
case 15:
case 16:
rgb_size[0] = 5;
rgb_size[1] = 5;
rgb_size[2] = 5;
break;
default:
rgb_size[0] = 8;
rgb_size[1] = 8;
rgb_size[2] = 8;
break;
}
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, rgb_size[0] );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, rgb_size[1] );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, rgb_size[2] );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 24 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
if ( SDL_SetVideoMode( w, h, bpp, video_flags ) == NULL ) {
fprintf(stderr, "Couldn't set GL mode: %s\n", SDL_GetError());
SDL_Quit();
exit(1);
}
}