j.bell730
April 8th, 2010, 08:26 PM
I'm trying to learn SDL and OpenGL. I'm just starting out creating simple 2d polygons (a triangle, actually). But nothing is showing up in the window. All I get is just a completely black window. I'm writing in C.
Here is my code:
#include "SDL/SDL.h"
#include <GL/gl.h>
#include <GL/glu.h>
int main (int argc, char* args[])
{
SDL_Surface* screen = NULL;
int screenWidth = 1024;
int screenHeight = 768;
int screenBPP = 32;
SDL_Init (SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
screen = SDL_SetVideoMode (screenWidth, screenHeight, screenBPP, SDL_SWSURFACE);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef (0.0f, 0.0f, 0.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f);
glVertex3f (0.0f, 1.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex3f (1.0f, -1.0f, 0.0f);
glColor3f (0.0f, 0.0f, 1.0f);
glVertex3f (-1.0f, -1.0f, 0.0f);
glEnd ();
SDL_Flip (screen);
SDL_Delay (3000);
SDL_Quit ();
return 0;
}
I'm compiling with:
gcc sdl.c -lSDL -lGL
What is it that I'm doing wrong?
Here is my code:
#include "SDL/SDL.h"
#include <GL/gl.h>
#include <GL/glu.h>
int main (int argc, char* args[])
{
SDL_Surface* screen = NULL;
int screenWidth = 1024;
int screenHeight = 768;
int screenBPP = 32;
SDL_Init (SDL_INIT_EVERYTHING);
SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8);
screen = SDL_SetVideoMode (screenWidth, screenHeight, screenBPP, SDL_SWSURFACE);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glTranslatef (0.0f, 0.0f, 0.0f);
glBegin (GL_TRIANGLES);
glColor3f (1.0f, 0.0f, 0.0f);
glVertex3f (0.0f, 1.0f, 0.0f);
glColor3f (0.0f, 1.0f, 0.0f);
glVertex3f (1.0f, -1.0f, 0.0f);
glColor3f (0.0f, 0.0f, 1.0f);
glVertex3f (-1.0f, -1.0f, 0.0f);
glEnd ();
SDL_Flip (screen);
SDL_Delay (3000);
SDL_Quit ();
return 0;
}
I'm compiling with:
gcc sdl.c -lSDL -lGL
What is it that I'm doing wrong?