OpenGL in SDL

Hey, guys.

Can anyone see anything wrong with the following code:

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <stdio.h>

int main() {
if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
atexit( SDL_Quit );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
SDL_WM_SetCaption( “OpenGL Cube”, “OpenGL Cube” );
glEnableClientState( GL_VERTEX_ARRAY );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
GLfloat all_vertices[] = { 0.0, 0.0, 10.0,
10.0, 0.0, 10.0,
10.0, 10.0, 10.0,
0.0, 10.0, 10.0,
0.0, 0.0, 0.0,
10.0, 0.0, 0.0,
10.0, 10.0, 0.0,
0.0, 10.0, 0.0 };
glVertexPointer( 3, GL_FLOAT, 0, all_vertices );
GLubyte all_indices[] = { 4, 5, 6, 7,
1, 2, 6, 5,
0, 1, 5, 4,
0, 3, 2, 1,
0, 4, 7, 3,
2, 3, 7, 6 };
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, all_indices );
glFlush();
SDL_GL_SwapBuffers;
SDL_Delay( 5000 );
return 0;
}

It compiles but doesn’t display anything on screen.

Thanks.

Mario de Sousa

Mario de Sousa wrote:

Hey, guys.

Can anyone see anything wrong with the following code:

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <stdio.h>

int main() {
if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
atexit( SDL_Quit );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
SDL_WM_SetCaption( “OpenGL Cube”, “OpenGL Cube” );
glEnableClientState( GL_VERTEX_ARRAY );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
GLfloat all_vertices[] = { 0.0, 0.0, 10.0,
10.0, 0.0, 10.0,
10.0, 10.0, 10.0,
0.0, 10.0, 10.0,
0.0, 0.0, 0.0,
10.0, 0.0, 0.0,
10.0, 10.0, 0.0,
0.0, 10.0, 0.0 };
glVertexPointer( 3, GL_FLOAT, 0, all_vertices );
GLubyte all_indices[] = { 4, 5, 6, 7,
1, 2, 6, 5,
0, 1, 5, 4,
0, 3, 2, 1,
0, 4, 7, 3,
2, 3, 7, 6 };
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, all_indices );
glFlush();
SDL_GL_SwapBuffers;

There is a pair of () missing here :slight_smile:

Stephane

Thanks a lot. Man that was stupid of me.

Thanks again.

Mario de SousaOn Fri, 13 Feb 2004 10:38:28 +0100 Stephane Marchesin <stephane.marchesin at wanadoo.fr> wrote:

Mario de Sousa wrote:

Hey, guys.

Can anyone see anything wrong with the following code:

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <stdio.h>

int main() {
if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
atexit( SDL_Quit );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
SDL_WM_SetCaption( “OpenGL Cube”, “OpenGL Cube” );
glEnableClientState( GL_VERTEX_ARRAY );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
GLfloat all_vertices[] = { 0.0, 0.0, 10.0,
10.0, 0.0, 10.0,
10.0, 10.0, 10.0,
0.0, 10.0, 10.0,
0.0, 0.0, 0.0,
10.0, 0.0, 0.0,
10.0, 10.0, 0.0,
0.0, 10.0, 0.0 };
glVertexPointer( 3, GL_FLOAT, 0, all_vertices );
GLubyte all_indices[] = { 4, 5, 6, 7,
1, 2, 6, 5,
0, 1, 5, 4,
0, 3, 2, 1,
0, 4, 7, 3,
2, 3, 7, 6 };
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, all_indices );
glFlush();
SDL_GL_SwapBuffers;

There is a pair of () missing here :slight_smile:

Stephane


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Thanks a lot. Man that was stupid of me.

Thanks again.

Mario de Sousa

Mario de Sousa wrote:

Hey, guys.

Can anyone see anything wrong with the following code:

#include <SDL/SDL.h>
#include <GL/gl.h>
#include <stdio.h>

int main() {
if ( SDL_Init( SDL_INIT_VIDEO ) != 0 ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
atexit( SDL_Quit );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
if ( SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ) == NULL ) {
printf( “%s\n”, SDL_GetError() );
return 1;
}
SDL_WM_SetCaption( “OpenGL Cube”, “OpenGL Cube” );
glEnableClientState( GL_VERTEX_ARRAY );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glClearColor( 0, 0, 0, 0 );
glClear( GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 0.0, 0.0 );
GLfloat all_vertices[] = { 0.0, 0.0, 10.0,
10.0, 0.0, 10.0,
10.0, 10.0, 10.0,
0.0, 10.0, 10.0,
0.0, 0.0, 0.0,
10.0, 0.0, 0.0,
10.0, 10.0, 0.0,
0.0, 10.0, 0.0 };
glVertexPointer( 3, GL_FLOAT, 0, all_vertices );
GLubyte all_indices[] = { 4, 5, 6, 7,
1, 2, 6, 5,
0, 1, 5, 4,
0, 3, 2, 1,
0, 4, 7, 3,
2, 3, 7, 6 };
glDrawElements( GL_QUADS, 24, GL_UNSIGNED_BYTE, all_indices );
glFlush();
SDL_GL_SwapBuffers;

There is a pair of () missing here :slight_smile:

Stephane


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl
I think you need to still set the viewport, it might be rendering off
screen.On 2/13/04 3:50 AM, “Mario de Sousa” wrote:
On Fri, 13 Feb 2004 10:38:28 +0100 Stephane Marchesin <stephane.marchesin at wanadoo.fr> wrote: