Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-25-2004, 08:59 PM
|
#1
|
Member
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547
Rep:
|
Quick question about OpenGL 'units'
Ok, I'm trying to learn OpenGL using the NeHe tutorials and there is still something I don't get and haven't been able to find a clear answer for (I did try to look on my own). If I do this:
Code:
glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
What the HECK is a unit??? I've been using pixels for all my calculations, and to me at least it seems a lot more convenient to think in terms of pixels rather than these units. Is there anyway to do a quick conversion so I can interpolate in terms of pixels rather than units? Thanks in advance for anyone who can clear this up for me.
|
|
|
07-26-2004, 05:32 AM
|
#2
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Rep:
|
Whatever you want it to be
If I have a real-world image (maybe a satellite image) then you will know the pixel resolution. From that you create your own scale, mapping it to a poly of the same ratio. You could map the whole earth this way to a unit sphere, or to 1000 times that. You just select the precision you want and keep this consistent, i.e. when calculating travelling speed or similar, and set the camera at an appropriate distance.
Bear in mind also that you want to make sure you don't start gettting precision errors, so keep the calculations within the realms of floating point accuracy. Think about the largest object you want to render and the smallest and create you coordinate system within the range of magnitudes, say 0.1 and 1000.
This isn't really any different from a pixel though. The actual size of a pixel is going to be several orders of magnitude different in my satellite image, compared to an image of, e.g. a brain cell taken through a microscope. One will have a pixel size of several metres (or cm if you work for the CIA  ), the other of several microns (assuming we even have square pixels!) even though both are 512 by 512 images.
I might want to map both to a polygon in OpenGL depending on whether I am building a model of the brain or the solar system, and both could be mapped to a 1 unit by 1 unit square. All I have to mentally remember is that I have used a unit as a metre or a micron.
From a game programming point of view, you might want to think about how many textures you are going to use to cover a floor. You could cover 100 metres by 100 with a 256 x256 texture. If your characters are human, this is going to look pretty blocky up close. On the other hand you could use the same texture to cover 10cm by 10cm. In which case you are going to use loads of texture memory (assuming varying terrain, that is and ignoring things like texture repetition with GL_REPEAT, IIRC) and take up thoudands of poly's but will give you fantastic detail. In reality you can combine both so that near features have loads of high detail poly's and texture, in the distance you use far fewer (google for Level of Detail or LOD). Whether these polys are 0.0001 units, 1 units or 1000 units is up to you though.
Hope that isn't too confusing.
Last edited by dakensta; 07-26-2004 at 05:37 AM.
|
|
|
07-26-2004, 06:30 AM
|
#3
|
Member
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547
Original Poster
Rep:
|
It's too confusing.
Ok, so I get why this would be useful for representing different distance scalings and whatever. I'm planning to use OpenGL for the project in my signature. Since sometimes we will be in a 'tiled' mode, sometimes in a battle mode, and sometimes in a menu mode I can't really see the benefit of having a set metric, unless I let 0.1 represent a single pixel or something. My game isn't 3D so I don't think I'll be doing much drawing with polygons. Mostly just creating bit-mapped flat surfaces. I dunno, I just can't see the usefulness of this unit type system for my particular application. Maybe I just need to read some more to understand this. 
|
|
|
07-26-2004, 12:11 PM
|
#4
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Rep:
|
Are you drawing onto the screen with glRead/Draw/CopyPixels and using OpenGL to provide a blitting surface?
I had thought you would be creating your background, characters etc. as polys, and rendering using an orthographic projection.
Perhaps you could give a quick example of something you want to do or where things are causing problems (not necessarily code) so I, or others, can give a better or at least more suitable explanation?
|
|
|
07-26-2004, 03:23 PM
|
#5
|
Member
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547
Original Poster
Rep:
|
I don't know what functions I'm using yet. I'm still reading thru the OpenGL redbook and NeHe tutorials to figure out things. Here's an example of what I want to do:
Map mode
Takes several 32x32 pixel tiles and draws a tiled map for a 1024x768 screen. I also want to be able to take this screen and resize it to fit other resolutions, but I don't want to create more or less of a viewing area (so basically I just want to resize the whole image before I flip it to the screen). And then there will be some sprites and other fun stuff.
Battle mode
Draw a background (single image, not tiled). Put 1-4 character sprites on top of that, as well as a variable number of enemy sprites. And then add cool graphical effects and show people running up and slicing their opponents in half and stuff
Menu mode
Just like your standard menu where you can select options, use items, etc.
Final Fantasy VI is the closest thing (graphically) to how my game will be. Thanks for the help dakensta!
|
|
|
07-26-2004, 04:48 PM
|
#6
|
Member
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194
Rep:
|
Hmm, you might want to look into using SDL (if you aren't already) - I am pretty sure that has plenty of sprite drawing capabilities built in (which I guess covers the FF6 from the screenshot I looked at) - a quick google turned up this: http://www.grinninglizard.com/kyra/ - click on the engine link for a nice description.
If you want to stick with raw OpenGL, you might want to flick through this thread (on the Gamedev OpenGL forum FAQ):
http://www.gamedev.net/community/for...25&WhichPage=2
and (it's a big PDF though, ~1.6Mb, image intensive) this explains projection pretty clearly with some good example images:
http://www.cs.dal.ca/~sbrooks/csci31...ections-x2.pdf
Personally I found "The Red Book" better than NeHe (but that's just opinion) and it is available online.
Anyway, the scaling thing should become a bit more obvious as you gain experience but this is a bit more specific ... plenty of people here better placed to advise about practical issues with OpenGL.
|
|
|
07-26-2004, 06:40 PM
|
#7
|
Member
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547
Original Poster
Rep:
|
Yes I'm using SDL. At first I was using SDL without OpenGL, but after a posting on the SDL newsgroup about image resizing I found out that doing so would greatly reduce the game's performance on any system, even a fast one. The people there said its actually quite popular to design a 2D game with advanced video hardware capabilities, and after my initial research I think they are right. I know about kyra, but my team decided it would be better to build our own sprite image.
I am also finding the NeHe tutorials to be a little bland, after going thru the first 5 lessons. I downloaded the redbook yesterday so I just need to find the patience to sit down and read thru it.  Thanks again for your help.
|
|
|
07-26-2004, 07:09 PM
|
#9
|
Member
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547
Original Poster
Rep:
|
Ah! That's exactly what I was looking for! Man I even spent time going through the documentation at opengl.org and couldn't find this. Thanks a lot 
|
|
|
All times are GMT -5. The time now is 10:10 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|