Jump to content
  • Advertisement

Why does this opengl sdl c code produce a blank screen

Recommended Posts

Hi I am trying to learn sdl 1 and open gl on linux, I have this  c code.



int main()

/*Inintialize SDL as usual */
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Error: %s\n", SDL_GetError());
return 1;


/* Enable OpenGL double buffering */

/*Set the colour depth (16 bit 565). */
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);

/* Create a 640 x 480, 16 bit window with support for
Open GL rendering. Unfortunately we won't know whether
this is hardware accelerated. */
if (SDL_SetVideoMode(640, 480, 16, SDL_OPENGL) == NULL) {
printf("Error: %s\n", SDL_GetError());
return 1;

SDL_WM_SetCaption("OpenGL with SDL!", "OpenGL");

/* We can now use any OpenGL rendering commands */

glViewport(80, 0, 480, 480);
glColor3f(1.0, 0, 0);
glVertex3f(0.0, 1.0, -2.0);
glColor3f(0, 0, 1.0);
glVertex3f(1.0, -1.0, -2.0);
glColor3f(0, 0, 1.0);
glVertex3f(-1.0, -1.0, -2.0);

/*Display the back buffer to the screen */

/*Wait a few seconds. */

return 0;



why is it producing just a blank screen, it compiled fine with gcc linking to -lSDL and -lGL, did I miss any, also I ran glxinfo | grep "version"

to see which version of opengl I got.



server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
    Max core profile version: 3.3
    Max compat profile version: 3.0
    Max GLES1 profile version: 1.1
    Max GLES[23] profile version: 3.0
OpenGL core profile version string: 3.3 (Core Profile) Mesa 18.2.2
OpenGL core profile shading language version string: 3.30
OpenGL version string: 3.0 Mesa 18.2.2
OpenGL shading language version string: 1.30
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 18.2.2
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00





Please help me get started and get some shapes on my screen. Thanks.








Share this post

Link to post
Share on other sites

Please, do not use those OpenGL commands, they're like 15+ years old.  Please look at the hundreds of OpenGL 3.0+ tutorials and examples out there.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!