3 #include <SDL/SDL_opengl.h>
7 const int SCREEN_WIDTH = 640;
8 const int SCREEN_HEIGHT = 480;
9 const int SCREEN_BPP = 32;
12 void draw_line(int, int);
13 void maneja_eventos();
15 int main(int argc, char *argv[])
26 SDL_Event event; //The event structure
29 //While the user hasn't quit
32 //If there's events to handle
33 if( SDL_PollEvent( &event ) )
39 if( event.type == SDL_MOUSEMOTION )
41 //Get the mouse offsets
48 //If the user has Xed out the window
49 if( event.type == SDL_QUIT )
65 glClearColor( 0, 0, 0, 0 );
68 glMatrixMode( GL_PROJECTION );
70 glOrtho( 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1 );
72 //Initialize modelview matrix
73 glMatrixMode( GL_MODELVIEW );
76 //If there was any errors
77 if( glGetError() != GL_NO_ERROR )
82 //If everything initialized
89 if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
95 if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
107 SDL_WM_SetCaption( "OpenGL Test", NULL );
112 void draw_line(int x, int y)
114 // Clear the screen before drawing
115 glClear( GL_COLOR_BUFFER_BIT );
117 float lineWidth = 1.0;
118 // set the line width
119 glLineWidth(lineWidth);
125 glVertex3f( SCREEN_WIDTH/2, 20, 0 );
126 glVertex3f( SCREEN_WIDTH/2,SCREEN_HEIGHT - 20, 0 );
128 glVertex3f( SCREEN_WIDTH - 20, SCREEN_HEIGHT/2, 0 );
129 glVertex3f( 20, SCREEN_HEIGHT/2,0 );
132 glVertex3f( 100, 100, 0 );
133 glVertex3f( x, y, 0 );