LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 07-25-2004, 08:59 PM   #1
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Rep: Reputation: 30
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.
 
Old 07-26-2004, 05:32 AM   #2
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
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.
 
Old 07-26-2004, 06:30 AM   #3
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Original Poster
Rep: Reputation: 30
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.
 
Old 07-26-2004, 12:11 PM   #4
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
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?
 
Old 07-26-2004, 03:23 PM   #5
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Original Poster
Rep: Reputation: 30
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!
 
Old 07-26-2004, 04:48 PM   #6
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
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.
 
Old 07-26-2004, 06:40 PM   #7
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Original Poster
Rep: Reputation: 30
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.
 
Old 07-26-2004, 07:05 PM   #8
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
Scroll down to 9.030 - it tells you how to setup 1 pixel units:

http://www.opengl.org/resources/faq/...formations.htm
 
Old 07-26-2004, 07:09 PM   #9
R00ts
Member
 
Registered: Mar 2004
Location: Austin TX, USA
Distribution: Ubuntu 11.10, Fedora 16
Posts: 547

Original Poster
Rep: Reputation: 30
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gnu units denning Slackware 2 02-24-2005 08:14 AM
I can see shared units on Windows boxes, but can't see any files within these units emiliofil Linux - Networking 2 01-24-2005 08:13 AM
opengl and frame speed - quick question tw001_tw Slackware 8 01-03-2005 08:18 PM
Units/blocks/heads/cylinders ???? leighsd Linux - Newbie 1 12-11-2003 12:25 PM
HELP: scsi emulation for BOTH units liam5150 Linux - General 3 07-18-2003 06:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:10 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration