Jump to content
  • Advertisement
Sign in to follow this  
ManaStone

OpenGL What considerations do I have to make when Switching from Glut to SDL?

This topic is 5053 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was using glut for doing windows and input and I finally got skeletal animation for my milkshape3D models to work right. Because I can’t use the mouse scroller for GLUT I decided to switch everything over to SDL. I only had to make a few minor changes, but now the animation transforms are looking really messed up(everything else seems to be fine). What could possibly have caused this problem from just switching from glut to sdl. This is the Glut version where the animation transforms work.
void myDisplay(void)
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
   glLoadIdentity();                  
  
   cam.setModelViewMatrix(); 


	glEnable(GL_TEXTURE_2D);
	


	sVertex v={3,10,0};
	cMatrix mat;
	mat.setToView();
	v=mat.transform(v);
	L.setPosition(v.x,v.y,v.z,0);
	tree.drawBounds();


	glPushMatrix();	
		glTranslatef(cam.at.x,cam.at.y-10,cam.at.z);
		Mage.Render();
	glPopMatrix();

	tree.render();


	glutSwapBuffers();
	glutPostRedisplay();  
	glFlush();
	
	static int lasttime=0;
	
	int time;
	time=glutGet(GLUT_ELAPSED_TIME);

	fr++;

	
	if((time-lasttime)>1000)
	{
	 lasttime=time;
	 lfr=fr;
	 fr=0;
  	 time=0;
	

	}
}
void keyboard (unsigned char key, int x, int y)
{
	static cTimer tm;
	float ang= 2;
	float speed =lfr * (.02);
switch (key) {
case 'a':
	{
	cam.yaw(-ang);
	
	}break;

case 'd':
	{
	cam.yaw(ang);

	}break;
case 'q':
	{
		cam.pitch(-ang);
     //	cam.RotUp(ang);
	}break;
case 'e':
	{
		cam.pitch(ang);
     //	cam.RotUp(ang);
	}break;
case 'w':
	{
	
	cam.move(-speed);
//	cam.move(0.5);
	}break;
case 's':
	{
	cam.move(speed);
	}break;
case 'z':
	{
	cam.roll(-ang);
//	cam.strafe(0.5);
	}break;
case 'c':
	{
	cam.roll(ang);
//	cam.strafe(-0.5);
	}break; 
case 'k':
	{
	cam.down(-speed);
//	cam.strafe(0.5);
	}break;
case 'i':
	{
	cam.down(speed);
//	cam.strafe(-0.5);
	}break; 

case 'j':
	{
//	cam.down(-speed);
	cam.strafe(-0.5);
	}break;
case 'l':
	{
//	cam.down(speed);
	cam.strafe(0.5);
	}break; 
case 'm':
	{
//	cam.down(speed);
	cam.rotate(5);
	}break; 
case 'n':
	{
//	cam.down(speed);
	cam.rotate(-5);
	}break; 
case 'o':
	{
cout<<"Starting Timer"<<endl;
	tm.restart();
	cout<<tm.getTime()<<endl;
	}break; 
case 'p':
	{
	cout<<tm.getTime()<<endl;
	}break; 
default:
break;
}


}
void main(int argc, char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowSize(800,600);
	glutCreateWindow("blah");
	glutDisplayFunc(myDisplay);
	glutKeyboardFunc(keyboard);
	myInit();

	glutMainLoop();
	
	glDisableClientState(GL_VERTEX_ARRAY);


}



These are the SDL changes I've made and the only thing about the code that I have changed.


void myDisplay(void)
{
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);   
        glLoadIdentity();                  
  
       cam.setModelViewMatrix(); 


	glEnable(GL_TEXTURE_2D);
	


	sVertex v={3,10,0};
	cMatrix mat;
	mat.setToView();
	v=mat.transform(v);
	L.setPosition(v.x,v.y,v.z,0);
	tree.drawBounds();
	


	glPushMatrix();	
		glTranslatef(cam.at.x,cam.at.y-10,cam.at.z);
		Mage.Render();
	glPopMatrix();


	tree.render();


	SDL_GL_SwapBuffers();
	glFlush();
	static int lasttime=0;
	
	int time;
	time=SDL_GetTicks();

	fr++;

	
	if((time-lasttime)>1000)
	{
 //    cout<<fr<<endl;
	 lasttime=time;
	 lfr=fr;
	 fr=0;
  	 time=0;
	

	}
	

}

void keyboard ()
{
	static cTimer tm;
	float ang= 2;
	float speed =lfr * (.02);

	static Uint8 *keylist = SDL_GetKeyState(NULL);
    
	SDL_PumpEvents(); 




	if(keylist[SDLK_a])
	{
		cam.yaw(-ang);
	
	}

	if(keylist[SDLK_d])
	{
		cam.yaw(ang);

	}
	if(keylist[SDLK_q])
	{
			cam.pitch(-ang);
     //	cam.RotUp(ang);
	}
	if(keylist[SDLK_e])
	{
		cam.pitch(ang);
     //	cam.RotUp(ang);
	}
	if(keylist[SDLK_w])
	{
		cam.move(-speed);
//	cam.move(0.5);
	}
	if(keylist[SDLK_s])
	{
		cam.move(speed);
	}
	if(keylist[SDLK_z])
	{
		cam.roll(-ang);
//	cam.strafe(0.5);
	}
	if(keylist[SDLK_c])
	{
		cam.roll(ang);
//	cam.strafe(-0.5);
	} 
	if(keylist[SDLK_k])
	{
		cam.down(-speed);
//	cam.strafe(0.5);
	}
	if(keylist[SDLK_i])
	{
		cam.down(speed);
//	cam.strafe(-0.5);
	} 

	if(keylist[SDLK_j])
	{
//	cam.down(-speed);
		cam.strafe(-0.5);
	}
	if(keylist[SDLK_l])
	{
//	cam.down(speed);
		cam.strafe(0.5);
	}
	if(keylist[SDLK_m])
	{
//	cam.down(speed);
		cam.rotate(5);
	} 
	if(keylist[SDLK_n])
	{
//	cam.down(speed);
		cam.rotate(-5);
	}



}

void Init_SDL(int height,int width)
{
	const SDL_VideoInfo* info = NULL;
    
    int bpp = 0;
    int flags = 0;

    SDL_Init( SDL_INIT_VIDEO );
 
   
    info = SDL_GetVideoInfo( );


    bpp = info->vfmt->BitsPerPixel;

 

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );


    flags = SDL_OPENGL ;

	SDL_SetVideoMode( width, height, bpp, flags ) ;

}

int main(int argc, char** argv)
{

	Init_SDL(600,800);
	bool running=true;
	SDL_Event event;
	myInit();

		while( running)
    {
        SDL_PollEvent( &event);
        
        if(event.type == SDL_QUIT)
            running = false;
	
		keyboard();
		myDisplay();

    }
	
	glDisableClientState(GL_VERTEX_ARRAY);
    atexit(SDL_Quit);

return 0;
}



Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!