Jump to content

  • Log In with Google      Sign In   
  • Create Account


Scrolling in OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 oscarcat   Members   -  Reputation: 105

Like
0Likes
Like

Posted 04 September 2012 - 04:57 AM

Hi, i'm creating a simple adventure game where the player just walks around different rooms, and when they hit door, the game refreshes to a new room.


Each room size is 600x400 and the game consists of 3 rooms. The window only displays 1 room at a time.
I've worked through most of the tutorials on lazyfoo and here for scrolling, but i can only find tutorials that moves the camera with the player in the center.


I tried using translatef as shown in the tutorials but it just distorts the room and if i try to create QUADS that goes beyond 600x400 it does not display, even when i call glTranslatef() to the position.

Sorry if this is a little hard to understand, hopefully this diagram will make my post easier to follow:

Posted Image

Here are relevant code snippet
bool init()
{
	 //relevant init code
	 glViewport(0, 0, 600, 400);
	 glMatrixMode(GL_PROJECTION);
	 return true;
}
void render()
{
	  //relevant render code
	  glClear(GL_COLOR_BUFFER_BIT);
	  glPushMatrix();
	  glOrtho(0,600,400,0,-1,1);
	 if (player->room == 1)
		 glTranslatef(0, 0, 0);
	 if(player->room == 2)
		 glTranslatef(-600, 0, 0); //pan camera right 600px
	 if(player->room == 3)
		  glTranslatef(0, -400, 0); //pan camera down 400px
	  //initialize all rooms and objects in the whole maze
	  glPopMatrix(); //End rendering phase
}
Any help would be appreciated, thanks.

Sponsor:

#2 rnlf   Members   -  Reputation: 1057

Like
2Likes
Like

Posted 04 September 2012 - 06:26 AM

From your code snippet it looks like you are rendering your scene while in GL_PROJECTION matrix mode? If you translate your projection matrix, funny effects (like distortion) may happen. Try a glMatrixMode(GL_MODELVIEW) at the beginning of your render() function.

Your projection matrix does not need to be changed all that often ;-)

Edited by rnlf, 04 September 2012 - 06:26 AM.

my blog (German)


#3 Lazy Foo   Members   -  Reputation: 1103

Like
1Likes
Like

Posted 04 September 2012 - 09:55 AM

What you probably want to do is when the camera gets close to the edge of the room it should lock inside the room.

Also, as mentioned in the OpenGL scrolling tutorial, you shouldn't be using the projection matrix to scroll your camera.
Learn to make games with my SDL Tutorials.
Transition from OpenGL 2 to modern OpenGL using my OpenGL Tutorial.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS