Archived

This topic is now archived and is closed to further replies.

Using GL for 2D

This topic is 5178 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''ve been working on a 2D tile-base RPG, and so far I''ve used DirectDraw. However, I''m eager to switch it to OpenGL. I''ve started docs on GL, but nowhere I could find 2d focused GL tutorials. I''ve 2 questions.. -Is there a way to load and use non-power-of-2-sized bitmaps? -I hope I can express this one; say I have a bitmap 256 by 256 and screen 640*480. I want to use GL as pure 2d. How can I make 256*256 bitmap as 256*256 on the screen?

Share this post


Link to post
Share on other sites
quote:

-Is there a way to load and use non-power-of-2-sized bitmaps?


Not by default, check the NV_texture_rectangle extension, it allows you to use non-power-of-two textures.
http://oss.sgi.com/projects/ogl-sample/registry/NV/texture_rectangle.txt

quote:

-I hope I can express this one; say I have a bitmap 256 by 256 and screen 640*480. I want to use GL as pure 2d. How can I make 256*256 bitmap as 256*256 on the screen?



Setup an orthographic projection. (See redbook or the "Masking an Ortho Mode" Tutorial on http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg2.htm).
Then draw a quad with 256,256 extents and texture it with you bitmap.

// In case you use non-power-2 textures

glBindTexture(GL_TEXTURE_RECTANGLE_NV, texID );

glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f);
glVertex2f(0,0);

glTexCoord2f(1,0);
glVertex2f( width,0.0f);

glTexCoord2f(1,1);
glVertex2f( width, height);;

glTexCoord2f(0,1);
glVertex2f(0.0f,height);

glEnd();







eisscholle.de

[edited by - stephanh on October 11, 2003 10:34:53 AM]

Share this post


Link to post
Share on other sites
1. yes you can, but only through recent extensions. If you can avoid using non-power-of-two textures, I would really do that.

2. use glOrtho2D to set the width and height of the viewspace to the width and height of the window. Then if you create a square 256x256 with the texture on it, each pixel in the texture will become a single pixel on the screen (note that if this is always the case, you don''t need to mipmap the textures).

Share this post


Link to post
Share on other sites
1) You can also use gluBuild2DMipmaps as it will resize it to the nearest power for you.

2) See above

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

Share this post


Link to post
Share on other sites
quote:
Original post by Raloth
Don''t use vender specific extensions...try this:

http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of_two.txt


oops. sorry, wasn''t aware of an ARB equivalent.

Share this post


Link to post
Share on other sites
Thanks, that solves the problem. As a GL lamer, I have some more 2d questions

-How can I get a certain piece of a texture into another texture? Ie, I load a tile set (which is non-power-of-two, and I need to break it into power-of-two pieces)
-I just want to discard black (0,0,0) pixels. I've looked around about masking in NeHe, and "Masking an Ortho Mode", but they seem to work..different. Again, what I'm trying to do is to discard black pixels.


[edited by - Cortez on October 12, 2003 7:03:55 AM]

Share this post


Link to post
Share on other sites
Instead of colour keying, use alpha blending or testing. This means your textures need an alpha channel. Either create this in your image editing program (.png is nice to work with) and load it in as RGBA (or similar) or do it at load time - any pixels with a colour of black become alpha 0, others are alpha 1.

Then you use blending or testing to remove your black pixels. Making the alpha in an actual image program will give nicer results though.

Share this post


Link to post
Share on other sites