Skip to main content
gamedev.net
🔒 Locked

Problem concerning OpenGL + SDL

Started by darrenctwhk Jan 21, 2007 at 9:49 AM 5 replies 950+ views
Original Post
darrenctwhk
darrenctwhk
Hi guys. Please help me to solve this problem When I am using kdevelop to create a simple demostration of drawing simple polygon by opengl and SDL . It kept render blank frame no matter how I modify the code except when i call glClearColor , The frame become the corresponding color . But when i want to render some polygons it kept render blank frame...what's the problems??? who can help me ,please
AndyEsser
AndyEsser
It would be more help if you posted some code
DMINATOR
DMINATOR
Yes the first thing to do in this cases is change position of your camera or object, like that :

glTranslatef( 0.0f , 0.0f, - 5.0f );
darrenctwhk
darrenctwhk
Quote:
Original post by DMINATOR
Yes the first thing to do in this cases is change position of your camera or object, like that :

glTranslatef( 0.0f , 0.0f, - 5.0f );


I am sure i have included this line in my code

I wrote somethings like this:

void init_gl()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,800.0/600.0,1.0,1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glViewport(0,0,800,600);

...

return;
}

void render()
{
glClear( //flags to clear the buffer);

glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_QUADS);
glColor3f(1.0,0.0,0.0);
glVertex3f(-1.0,1.0,0.0);
glVertex3f(1.0,1.0,0.0);
glVertex3f(1.0,-1.0,0.0);
glVertex3f(-1.0,-1.0,0.0);
glEnd();
glPopMatrix();

...

//swapBuffer
return ;
}

Also, I compile and run this demostration under Windows
It render the according polygons

With the same code i compile and run it under linux,
it kept render the blank frame....

Is it something to do with the initialisation of SDL???

help!!!please!!!
sjoerd222
sjoerd222
Linux should work the same way, SDL is portable.

For posting code use brackets: [?source?] CODE [/?source?] (you should drop the "?"'s)

Try "glxgears" in commandline once and tell me what happens. I suppose your 3D driver is not installed correctly.

But supose everything's working fine, try this code once:
#include <SDL/SDL.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <GL/gl.h>#include <GL/glu.h>#define TRUE  1#define FALSE 0int init_GL( GLvoid ){	// Enable smooth shading 	glShadeModel( GL_SMOOTH );	// Set the background black 	glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );	// Depth buffer setup 	glClearDepth( 1.0f );	// Enables Depth Testing	glEnable( GL_DEPTH_TEST );	// The Type Of Depth Test To Do	glDepthFunc( GL_LEQUAL );	// Really Nice Perspective Calculations	glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );	return 1;}int draw_GL(GLvoid)                // Here's Where We Do All The Drawing{		// These are to calculate our fps	static GLint T0     = 0;	static GLint Frames = 0;	// Clear The Screen And The Depth Buffer	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );	// Move Left 1.5 Units And Into The Screen 6.0	glLoadIdentity();	glTranslatef( -1.5f, 0.0f, -6.0f );	glRotatef(50,0.0f,1.0f,0.0f);                         // Rotate The Pyramid On It's Y Axis	glBegin( GL_TRIANGLES );            // Drawing Using Triangles 	glColor3f(1.0f,0.0f,0.0f);                      // Red	glVertex3f( 0.0f, 1.0f, 0.0f);                  // Top Of Triangle (Front)	glColor3f(0.0f,1.0f,0.0f);                      // Green	glVertex3f(-1.0f,-1.0f, 1.0f);                  // Left Of Triangle (Front)	glColor3f(0.0f,0.0f,1.0f);                      // Blue	glVertex3f( 1.0f,-1.0f, 1.0f);                  // Right Of Triangle (Front)	glColor3f(1.0f,0.0f,0.0f);                      // Red	glVertex3f( 0.0f, 1.0f, 0.0f);                  // Top Of Triangle (Right)	glColor3f(0.0f,0.0f,1.0f);                      // Blue	glVertex3f( 1.0f,-1.0f, 1.0f);                  // Left Of Triangle (Right)	glColor3f(0.0f,1.0f,0.0f);                      // Green	glVertex3f( 1.0f,-1.0f, -1.0f);                 // Right Of Triangle (Right)	glColor3f(1.0f,0.0f,0.0f);                      // Red	glVertex3f( 0.0f, 1.0f, 0.0f);                  // Top Of Triangle (Back)	glColor3f(0.0f,1.0f,0.0f);                      // Green	glVertex3f( 1.0f,-1.0f, -1.0f);                 // Left Of Triangle (Back)	glColor3f(0.0f,0.0f,1.0f);                      // Blue	glVertex3f(-1.0f,-1.0f, -1.0f);                 // Right Of Triangle (Back)	glColor3f(1.0f,0.0f,0.0f);                      // Red	glVertex3f( 0.0f, 1.0f, 0.0f);                  // Top Of Triangle (Left)	glColor3f(0.0f,0.0f,1.0f);                      // Blue	glVertex3f(-1.0f,-1.0f,-1.0f);                  // Left Of Triangle (Left)	glColor3f(0.0f,1.0f,0.0f);                      // Green	glVertex3f(-1.0f,-1.0f, 1.0f);                  // Right Of Triangle (Left)    glEnd( );                           // Finished Drawing The Triangle    // Move Right 3 Units    glTranslatef( 3.0f, 0.0f, 0.0f );    glBegin( GL_QUADS );                // Draw A Quad      glVertex3f( -1.0f,  1.0f, 0.0f );      glVertex3f(  1.0f,  1.0f, 0.0f );       glVertex3f(  1.0f, -1.0f, 0.0f );       glVertex3f( -1.0f, -1.0f, 0.0f );     glEnd( );                           // Done Drawing The Quad    /* Draw it to the screen */    SDL_GL_SwapBuffers( );    /* Gather our frames per second */    return( 1 );}int show_Window(GLvoid){	//Height / width ration 	GLfloat ratio;	// Protect against a divide by zero	ratio = ( GLfloat )1024 / ( GLfloat )768;	// Setup our viewport.	glViewport( 0, 0, ( GLsizei )1024, ( GLsizei )768 );	// change to the projection matrix and set our viewing volume. //	glMatrixMode( GL_PROJECTION );	glLoadIdentity( );	// Set our perspective	gluPerspective( 45.0f, ratio, 0.1f, 100.0f );	// Make sure we're chaning the model view and not the projection 	glMatrixMode( GL_MODELVIEW );	// Reset The View 	glLoadIdentity( );}int main (void) {		SDL_Surface *screen;	if (SDL_Init ( SDL_INIT_VIDEO ) != 0) {		printf ("Konnte SDL nicht initialisieren: %s\n",		SDL_GetError ());	return EXIT_FAILURE;	}	screen = SDL_SetVideoMode (1024, 768, 32,SDL_FULLSCREEN|SDL_OPENGL|SDL_HWPALETTE|SDL_GL_DOUBLEBUFFER);	if (screen == NULL) {	     printf ("Videomodus konnte nicht eingerichtet werden: "              " %s\n", SDL_GetError ());		return EXIT_FAILURE;	}	init_GL( );	show_Window( );	draw_GL( );	SDL_Delay (8000);	printf ("Erfolgreich beendet!\n");	//SDL_ListModes   return EXIT_SUCCESS;}
May the force be with... me! :-D

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.