Diplomtennis
2004.10.11, 11:31 PM
hi,
I just started with OpenGL & SDL and ran into the first problem right at the start. The following code is supposed to draw a triangle but the window remains black:
if ( SDL_Init(initflags) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
/* Initialize SDL */
SDL_GL_SetAttribute ( SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute ( SDL_GL_DOUBLEBUFFER, 1);
//set attributes for OpenGL
info = SDL_GetVideoInfo();
video_bpp = info->vfmt->BitsPerPixel;
// get infos for bpp
window=SDL_SetVideoMode(xsize,ysize, video_bpp, videoflags);
/* Set video mode */
if (window == NULL) {
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
SDL_Quit();
exit(2)
glClearColor (0,0,0,0);
// sets clear color to black
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// clears gl buffer
glLoadIdentity();
// resets identity
glTranslatef(0.0f,0.0f,-5.0f);
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,-1.0f, 1.0f); // Top
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right
glEnd();
SDL_GL_SwapBuffers();
I kinda copied this together and it should be exactly the source code from the SDL docs plus the Nehe tutorials and I really wonder why it is not working. My guess is that I forgot something. But what?
thanks. d
I just started with OpenGL & SDL and ran into the first problem right at the start. The following code is supposed to draw a triangle but the window remains black:
if ( SDL_Init(initflags) < 0 ) {
fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
exit(1);
/* Initialize SDL */
SDL_GL_SetAttribute ( SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute ( SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute ( SDL_GL_DOUBLEBUFFER, 1);
//set attributes for OpenGL
info = SDL_GetVideoInfo();
video_bpp = info->vfmt->BitsPerPixel;
// get infos for bpp
window=SDL_SetVideoMode(xsize,ysize, video_bpp, videoflags);
/* Set video mode */
if (window == NULL) {
fprintf(stderr, "Couldn't set video mode: %s\n", SDL_GetError());
SDL_Quit();
exit(2)
glClearColor (0,0,0,0);
// sets clear color to black
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// clears gl buffer
glLoadIdentity();
// resets identity
glTranslatef(0.0f,0.0f,-5.0f);
glBegin(GL_TRIANGLES);
glVertex3f(-1.0f,-1.0f, 1.0f); // Top
glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left
glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right
glEnd();
SDL_GL_SwapBuffers();
I kinda copied this together and it should be exactly the source code from the SDL docs plus the Nehe tutorials and I really wonder why it is not working. My guess is that I forgot something. But what?
thanks. d