Jump to content
  • Advertisement
Sign in to follow this  
Nositi

OpenGL Setting up iso/ortho view

This topic is 3934 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

Hello, This is my first post, and I'm very much new to OpenGL and anything pertaining to 3D. I would have responded to the post here: http://www.gamedev.net/community/forums/topic.asp?topic_id=319421 if it were not long retired. Essentially, I'm trying to create a pseudo-isometric view. I don't think it would truly be considered isometric, because I want to be able to rotate the landscape. I hope this is clear. I am thinking of something similar to what is utilized in Final Fantasy Tactics. Anyway, I've followed the NeHe tutorials and can't seem to get it set up properly. I tried following the advice posted in the link provided, but for some reason I seem to be having trouble creating a quad in the correct location. Here's what I have so far (modifying code from one of the NeHe tutorials):
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	// make sure there is no divide by 0
	if (height == 0)
		height = 1;

	glViewport(0, 0, width, height);

	
	// select projection matrix
	glMatrixMode(GL_PROJECTION);
	// reset projection matrix
	glLoadIdentity();

	glOrtho(0.0f, width, height, 0.0f, -1.0f, 1.0f);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}


int DrawGLScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
        
        glRotatef(35.264f, 1.0f, 0.0f, 0.0f);
	glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);
        
        gluLookAt(10.0f, 8.0f, 20.0f, 10.0f, 8.0f, 0.0f, 0.0f, 1.0f, 0.0f);
	
        glBegin(GL_QUADS);
	glVertex3f(0.025f, 0.025f, 0.0f);
	glVertex3f(0.975f, 0.025f, 0.0f);
	glVertex3f(0.975f, 0.975f, 0.0f);
	glVertex3f(0.025f, 0.975f, 0.0f);
	glEnd();


What might I be doing horribly wrong? EDIT: By "correct location", I mean I can't create anything that I can actually see. I've tried adding the functionality to rotate along each axis, but I still can't see anything after having rotated throughout the whole thing. [Edited by - Nositi on January 7, 2008 12:11:03 AM]

Share this post


Link to post
Share on other sites
Advertisement
theres a lot wrong wit what youve posted, check out a simple working opengl example, eg from libsdl.org or nehe

u should have someit like

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt(2,2,2, 0,0,0, 0.0f, 1.0f, 0.0f);

glBegin(GL_QUADS);
glVertex3f(-1, 0, -1);
glVertex3f(1, 0, -1);
glVertex3f(1, 0, 1);
glVertex3f(-1, 0,1 );
glEnd();

Share this post


Link to post
Share on other sites
Thanks for the response.

I'm not trying to set it up for 2D though, I've managed to figure that out. I've gone over a lot of the NeHe tutorials including tutorial 21, which involves making a 2D game.

I'll attempt to explain what I'm trying to do a bit better. Here's what I've created with the perspective view: http://img2.freeimagehosting.net/uploads/9b7b9c479a.jpg

I've rotated -55 on the x axis, and then I can rotate on the z axis to spin the whole grid, which is centered on 0, 0, 0.

This is essentially what I'm trying to do, but I don't want to be using gluPerspective. I want to use glOrtho, so that the further away squares are the same size on the screen as the close ones. That is, I want it to look more like this: http://upload.wikimedia.org/wikipedia/en/a/a8/BattleGrid.jpg

The retired topic that I linked to in my initial post has code that is supposed to allow this, and I tried to adapt it (in the code I provided), but it's not working. I haven't managed to find any similar resources and I just can't get this to work, which means I must be missing something.

Share this post


Link to post
Share on other sites
Alright thanks, I will try there. I thought this forum would be good because I'm specifically trying to set up the view with OpenGL, but maybe it would be better to ask there.

Share this post


Link to post
Share on other sites
Hi, I've never done what you're trying to do but as far as I know glOrtho is declared as something like glOrtho(left, right, bottom, top, zNear, zFar); From which
zNear, zFar - "Specify the distances to the nearer and farther depth clipping planes. These values are negative if the plane is to be behind the viewer."

In your code I see value like like -1 for zNear and 1 for zFar. This can be a problem if you're loooking at the scene from more than a distance of 1. So try increasing the zFar value, like glOrtho(0.0f, width, height, 0.0f, 1.0f, 1000.0f); and also make sure you are looking at the scene (with gluLookAt). Maybe I'm totally wrong, but I still hope I could help a bit.

Share this post


Link to post
Share on other sites
Thanks jaybee. I managed to get it fixed, and that was part of it. I think I got that line of code from the NeHe tutorial, and it didn't fit the context here. I was also drawing on the wrong axes - x and z when it should have been x and y.

Share this post


Link to post
Share on other sites
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!