Getting A Classic Zelda View

Moderator
Posts: 608
Joined: 2002.04
Post: #16
Code:
gluOrtho2D(0, game_width, game_height, 0);
This will set 0, 0 to the top left of the screen, so the X axis goes right and positive and the Y axis goes down and negative (I'm not sure if that made any sense...).
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #17
Ok so if I subtract from a Y value it will still go down. Ok.

How can I get things to draw in the proper order visibly? (see my last post)
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #18
draw what you want on top after you draw what's on the bottom. Smile
Draw O first then P. It's like painting. Whatever you paint first will get covered by what you paint next.

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #19
Oh, I didn't know that worked but then again I've never been working with just 2 dimensions with OpenGL yet. Thanks.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #20
You can still submit the z coordinate if you want openGL to sort things for you. It won't change how things look on the screen, but it will tell openGL what layer you want to draw into.

Otherwise you can just turn of depth testing with glDisable(GL_DEPTH_TEST); and draw things in the order that you want them to appear.
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #21
I forgot to mention turning off the depth test, but yeah! If you are doing 2D and want good performance, it should be faster for you to do your own depth testing than letting OpenGL sort it out. Plus, if you want good alpha layering you'll end up having to do a lot of sorting yourself anyway. Smile

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Member
Posts: 233
Joined: 2003.05
Post: #22
Oh yeah and this might help you out too:
http://nehe.gamedev.net/data/lessons/les...?lesson=32
It's lesson 32 from the nehe tutorials and most of the questions you've had here are answered in it.

I think there is an SDL version (generic linux but can be fixed for mac quickly)

"Pay no attention to that man behind the curtain." - Wizard of Oz
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #23
aaronsullivan Wrote:I forgot to mention turning off the depth test, but yeah! If you are doing 2D and want good performance, it should be faster for you to do your own depth testing than letting OpenGL sort it out. Plus, if you want good alpha layering you'll end up having to do a lot of sorting yourself anyway. Smile

Why is it faster for me to do it? What is alpha layering? Does that have anything to do with transparency?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #24
Pretend for a second that you don't have a video card that can draw a billion pixels a second. Pretend you have a NES. How are you going to draw a pushable block on top of the floor tiles?

Put the Z-order of your objects into your map structure (or sprite structure, whichever) and just draw everything back-to-front.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #25
Ok that makes sense. What about the alpha layering? I've heard that term before but I'm not sure what it means.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #26
On a NES, sprite pixels are either there or they aren't. You had 4 pixel values per sprite, so typically three colors plus transparent.

In OpenGL you have 32* bits per pixel. 8 for red, green, blue, and alpha. The alpha determines the translucency. So a torch flame, drawn on top of a floor tile, could show part of the floor through it. Go read the GL spec for blending for more info (man glBlendFunc)

* assuming the old fixed function GL pipeline. Current video cards can allocate 128 color bits per pixel with floating point framebuffers. But this is only of use with fragment shader intermediate results, since all current consumer displays are 24 bpp.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #27
Ok that's cool and useful. Is there a way to designate the transparent color of my sprites?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #28
You can specify the alpha data per pixel exactly like you specify the color data, just use a bitmap format with an alpha channel like PNG or TIFF and an RGBA texture.

Or you can specify the alpha value per primitive with glColor4f.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #29
Ok cool. I'll give that a try. Is the alpha channel only a float or can I use glColor4ub?
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #30
4ub is fine.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  When to create custom OpenGL view instead of subclass NSOpenGL view Coyote 37 21,745 Oct 20, 2009 08:16 PM
Last Post: Coyote