Little opengl help

Started by
4 comments, last by JimmyFo 18 years, 12 months ago
i am createing a tile based game and currently i have a tile drawing function that draws tiles at there x,y locations but i recently implimented a tile scrolling method i was wondering how could i be like this tile is drawn top left of window next tile is drawn beside that one. the current for loop is set up like this (example of it i know that is not the syntax) for y for x draw code here if more info is needed just post and ask i would really like to know how to do this because if i change the map size right now i keep having to translate the pictures because they are drawn offscreen or something like that :) thanks i am using open GL and c++
Advertisement
That's really confusing - I assume you're using gluOrtho2D? That makes things a breeze if you have no need for the Ortho or the other matrices. Please provide some more information first: bmp or pixel, camera movement? What do you mean by tile scrolling?
no i build this off the NeHe tutorials so i guess i am just using a normal projection
Ok, I'm still a little confused, but if you are NOT using Ortho2D, then it becomes a bit more difficult to make sure the tile is at the right corner - basically, you'll need to do a little experimentation (or calculation beforehand) and have the tiles drawn out along whatever plane you want (probable the x/z plane) and then play with the camera till it contains only the tiles. You can find out the total area the tiles will take up and then use the camera angle to determine what will be seen.
ok well can i just alter my code to use that view and my draw function still work with changes or will it require MAJOR changes?

Any other methods?
It's tough because I'm not sure exactly where you're coming from - to change to Ortho2D, your display and reshape code will have no modelview matrix.

...
glViewport(...)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluOrtho2D(left, right, bottom, top)
...

The thing is, that makes for very simple paint programs and 2D interactive projects. However, it has lots of constraints. When you're using, say, gluPerspective along with the Projection and Modelview matrices, you have lots of flexibility, but something as exact as filling the screen and only the screen with what you want becomes much more difficult. Considering NeHe is very thorough, you probably have MFC and the 3D code, so what you should consider is perhaps creating tiles via GL_QUAD or GL_QUAD_STRIP in your display function and then maybe going for a nice camera angle. The Red book is very helpful in this matter.

This topic is closed to new replies.

Advertisement