Getting A Classic Zelda View
How can I get a classic Zelda view without the standard "distorting" of motion due to being full 3D with OpenGL? I'm really trying to get this down and implement it in a game I'm working on.
I've found that if I position my camera a ways up the Y axis and a little out the Z axis and look at the origin, it doesn't look too different (besides motion distortion). One thing I'm curious about is whether or not there is a way to create quads that a perpendicular to the camera's vector so that they appear perfect (whereas leaving them going straight along the Y axis would make the bottom look smaller)? If anybody knows how to create a method of fixing the motion distortion and how to make quads look perfect in this view, I would much appreciate it.
I have found that (see above post) to be a very inefficient way of getting the results I desire. I'm going to play a lot of Zelda, look at some screenshots, and then I'm going to try again.
have you tried using an orthographic projection matrix?
man glOrtho
man gluOrtho2D
man glOrtho
man gluOrtho2D
Thanks for the help Fenris. That's exactly what I need for the sprites. I'm looking into the gluOrtho2D and glOrtho right now and I'll let you know how that goes.
I've found a declaration of gluOrtho2D and glOrtho but I'm unsure how to use them and how they will help.
Code:
glMatrixMode(GL_PROJECTION);
// set to 800x600 view
glOrtho(0,600,800,0,-200,200);
glOrtho(left, right, bottom, top, near, far)
It's quite simple. The left right top and bottom parameters should be fairly self explanatory, the near and far set the minimum and maximum z coordinates.
glOrtho2D is the exact same thing, but it automatically puts in -1, and 1 for the near and far parameters.
It's quite simple. The left right top and bottom parameters should be fairly self explanatory, the near and far set the minimum and maximum z coordinates.
glOrtho2D is the exact same thing, but it automatically puts in -1, and 1 for the near and far parameters.
Here's my code so far and I'm not seeing anything on the screen:
Code:
void SizeOpenGLScreen(int width, int height) // Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero error
{
height=1; // Make the Height Equal One
}
glViewport(0,0,width,height); // Make our viewport the whole window
// We could make the view smaller inside
// Our window if we wanted too.
// The glViewport takes (x, y, width, height)
// This basically means, what our our drawing boundries
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
Code:
void RenderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The matrix
// Tell OpenGL where to point the camera
g_Camera.Look();
glBegin(GL_QUADS);
glColor3ub(255,255,255);
glVertex2f(-5,5);
glVertex2f(5,5);
glVertex2f(5,-5);
glVertex2f(-5,-5);
glEnd();
// Swap the backbuffers to the foreground
SDL_GL_SwapBuffers();
}
Use glOrtho(-10, 10, -10, 10, 1, 20); to set it up. Then do a translate like below:
glTranslatef(0.0f, 0.0f, -10.0f);
before you do any rendering (ie. one of the first lines in your render function).
This will set up your orthographic screen, and translate the camera out so that you can see it.
EDIT: Also, don't pass ints if you should be passing floats. In your glVertex2f() calls you are passing int values, which is just plain silly. Use (+-)5.0f, or call glVertex2i() instead.
glTranslatef(0.0f, 0.0f, -10.0f);
before you do any rendering (ie. one of the first lines in your render function).
This will set up your orthographic screen, and translate the camera out so that you can see it.
EDIT: Also, don't pass ints if you should be passing floats. In your glVertex2f() calls you are passing int values, which is just plain silly. Use (+-)5.0f, or call glVertex2i() instead.
for a more visual explaination check out http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html and scroll down to the section "Projection Transformations."
Typical 2D ortho projection is something like:
Since the Z coordinate doesn't mean anything in a 2D projection, you don't have to translate the camera out.
Also, this is perfectly fine:
because the int->float conversion will be handled at compile time.
This:
is not as good because now the conversion is at runtime. glVertex2i isn't really any better because all coordinates will be converted into floats internally anyway.
Code:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, game_width, game_height, 0); // origin in TOP left
glViewport(0, 0, window_width, window_height);
Since the Z coordinate doesn't mean anything in a 2D projection, you don't have to translate the camera out.
Also, this is perfectly fine:
Code:
glVertex2f(5,5);
This:
Code:
int x = 5, y = 5;
glVertex2f(x,y);
Thanks. That got it working. I also had a problem with the fact that my camera class was still setting itself up awkwardly not in the right position so (0,0) wound up at the top of the middle of the screen because the camera was putting itself at (0,0).
A couple more questions. This gluOrtho2D sets my upper left corner to (0,0) (in your example, arekkusu) and my lower right to (gamewidth,gameheight) correct? So why when I draw things they seem to ignore this and act as they usually would (for instance subtracting from Y seems like it should move up with 0 being the top but it still moves down)?
Edit:
Also, how can I make sure that things that are higher in Y are drawn above the objects with lower Y values to simulate the Zelda look? For example:
--------
-----O-
-----P-
-------
P is large enough to go into O, how do I get it to draw P above O and still draw O (so that when I put in sprites with transparency O is still visible)?
Edit:
Also, how can I make sure that things that are higher in Y are drawn above the objects with lower Y values to simulate the Zelda look? For example:
--------
-----O-
-----P-
-------
P is large enough to go into O, how do I get it to draw P above O and still draw O (so that when I put in sprites with transparency O is still visible)?
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
When to create custom OpenGL view instead of subclass NSOpenGL view | Coyote | 37 | 44,841 |
Oct 20, 2009 08:16 PM Last Post: Coyote |