I wrote a short OpenGL/SDL program (this is the first time I've done so). The program is based off the one in the OpenGL Red Book but, nothing is on screen when I run it.
Here's the code:
#include <stdio.h>
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
SDL_Surface *screen;
SDL_Event event;
int main(void)
{
SDL_Init(SDL_INIT_VIDEO); //Initilization
SDL_WM_SetCaption("\"Hello, World!\"", "\"Hello, World!\""); //The window caption is "Hello, World!"
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); //-+
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); // |
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); // |-Window attributes
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); // |
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); //-+
screen = SDL_SetVideoMode(640, 480, 16, SDL_OPENGL); //Create a window
//Drawing
//Setup
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//Polygon
glBegin(GL_POLYGON);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 240.0);
glVertex2f(320.0, 240.0);
glVertex2f(320.0, 0.0);
glEnd();
glFlush();
while(1)
{
glFlush();
SDL_Flip(screen); //Update the screen
}
return 0;
}