Hi I am trying to learn sdl 1 and open gl on linux, I have this c code.
#include<SDL/SDL.h>
#include<GL/gl.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
/*Inintialize SDL as usual */
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
printf("Error: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
/* Enable OpenGL double buffering */
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
/*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);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
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);
glEnd();
glFlush();
/*Display the back buffer to the screen */
SDL_GL_SwapBuffers();
/*Wait a few seconds. */
SDL_Delay(5000);
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.
Output:
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
P
Please help me get started and get some shapes on my screen. Thanks.