Jump to content
  • Advertisement

Archived

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

ma0

OpenGL A good OpenGL 2d Tutorial?

This topic is 6053 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

Where can I find a good 2d tutorial?? I''m playing with QUADS and textures, but I want to know if there is other good alternatives (glRect?How can I texture it?) Thanks ma0

Share this post


Link to post
Share on other sites
Advertisement
Thanks for the answer (U are the only who answered me)
I am now trying different solutions for a simple Tile *engine* (engine is a big word tough

- GL_QUADS + glTextCoords ( I''ve tried with gl_Rect but I dont know how to map a texture on it :-)

- gl_Drawpixels + glRasterPos

I want to test what''s the fastest solution..
Now I have some problem with the glRasterPos (I am not able to tile the entire screen..then I have to understand how to simulate the glTranslate..

I have a little question too.. how can I *create* a surface bigger than the screen, so if i translate, i always see something? I''ve tried changing the glViewport but then It changes the tile dimensions too..I don''t understand perfectly how they works.

Another BIG problem. how coordinates works? I''ve read many tutorials,but I don''t understand how to apply them. If I create a viewport of 640x480 and my cube is a 0.5,0.5,.. it will be half of the screen..how people can translate the diffent way of thinking coordinates?

Share this post


Link to post
Share on other sites
2D in OpenGL isn''t the greatest way to go. I would suggest you check out Simple DirectMedia Layer (SDL). There is a great tutorial on how to get it setup here on GameDev, its a featured article on the main page, and then go to cone3d.gamedev.net and take the SDL Graphics Tutorials.

This is a great alternative. SDL is very simple to use, and very easy to learn.

If you have any trouble with it (if you decide to use it), post your problem in the Cone3D forum, and you will be answered a.s.a.p.

SDL works with OpenGL, and there is alot of stuff you can do with it very simply, compared to how OpenGL does it.

Good luck.

Share this post


Link to post
Share on other sites
I use glOrtho with textured quads for my OpenGL-based tile engine :
http://rpg-forge.i8.com/screen_1.jpg


As you can see it looks the biz, and thanks to 3d acceleration you can do neat zooming in\out and loads of other effects.

Everyone has a 3d card nowadays.

Edited by - Terran Marine on December 14, 2001 2:34:09 AM

Edited by - Terran Marine on December 14, 2001 2:34:40 AM

Share this post


Link to post
Share on other sites
about SDL... I am using OpenGL because SDL unfortunately works fast only if I use it as root (on Linux) This is NO good.
I don''t like to use system ram instead of video ram and no hardware acceleration only because I am not root..
This is why I am trying to create some little example in OpenGL . Then I will translate it in SDL to show the difference..

ma0

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Terran Marine
I use glOrtho with textured quads for my OpenGL-based tile engine :
http://rpg-forge.i8.com/screen_1.jpg



Can I see some of your code? I have some problem to understan how glOrtho2D (i use the 2D form) and glView works together..I am using 64x64 tiles and I want to create a *terrain* bigger than the screen..but If i set glView bigger , my tiles becomes bigger..
--> How are related the -1.0..1.0 coords? they are glOrtho xmin->xmax or glView?
(example in 640x480 screen: glTranslatef(0.2,0.0,0.0) are 640/2+(1/640*0.2) ??)

Share this post


Link to post
Share on other sites
Don''t use glDrawPixels/glRasterPos - it chokes the graphics pipeline and can cause your FPS to drop about 4/5ths. Use GL_QUADs!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Generally, you will always want to set glViewport to the size of the window - that way the entire window will be used. If you enlarge the window but not the viewport, you''ll only be using a small portion of the new window.

A call to glOrtho2D is the same as a call to glOrtho with -1.0, 1.0 as the near and far clip planes. Remember, just because you are thinking in 2D, you are still drawing in 3D and the z axis does exist.

Now, you can thank of glOrtho as a way to map screen coordinates to pixel coordinates. If you reset the recatangle to start at (0,0) and use width and height of the window everytime you resize the screen, then your coordinates will range from (0,0) to (winWidth, winHeight).

So, to keep the images from stretching win the window is resized, call both glOrtho AND glViewport with the new window dimensions in your resize function. Otherwise, if you make glViewport bigger, but don''t update glOrtho, then you will have a larger viewport which maps to the original screen coordinates. That is, if you set the width/height of the viewport to (800,600), but glOrtho''s width/height are set to (640,480), then OpenGL will map the coordinates so that position (640,480) is actually (800/600) on the screen. Therefore, all of your images will be larger than you expect.

This is sometimes desirable. For example, if you have a game where you only want to display a row of 10 tiles at a time, just never call glOrtho after the first call, update glViewport each time the screen is resized, and you will always display the same number of tiles. They will be stretched to fit the window. If you have a scrolling game, you might instead update the viewport AND the projection each time the window is resized in order to show more of the map.

Share this post


Link to post
Share on other sites
It sounds like you want to be able to render a world that is say 1000x1000, but have a viewport that is 100x100, and scrolls over the world. I am assuming you want to do this because it should be faster than rendering each screen/view from scratch.

This is really just a blitting trick, and not handled by something like OpenGL. If you want to do that, then render to an offscreen surface, and then blit portions of that to the screen. This is of course assuming that you *can* render to an offscreen surface (not a backbuffer) and assuming that you dont lose the hardware acceleration if you do so.

As for being faster, sure it''s probably faster, but when modern day video cards can render millions of texture mapped triangles/second, I don''t think you''ll be stressing that limit with your average 2d game.


-Brannon

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!