🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

2D OpenGL tile-based boardgame

Started by
4 comments, last by lc_overlord 16 years, 2 months ago
I looked around here on the forum and didn't see anything that was helpful to me, so... My collegue and I want to create a tile-based board game, and want to use OpenGL to create the game world. We wanted to use Direct Draw initially, since it's naturally for 2D, but since we couldn't find any help on it we decided to use OpenGL instead. I must say I'm amazed with how much support there is for it here... I understand that OpenGL is probably best for 3D games, but we don't have enough time to spend a couple months developing a 3D game, nor do we want to. We thought OpenGL would have a wider range of capabilities than GDI, too. I have Lesson 1 working in .net, the basic GL window and such. We really need some help in getting a game board working. We're very familiar with C++ and .net, but reletively new to game programmming. We don't really know where to start, and none of the tutorials on this site really dealt much with 2d graphics, only 3d, so I was hoping someone with experiance could fill us in on what to do next. Much appreciated, ChiEkku
Advertisement
2d is just rendering a plne on the 3d world then put a texture on it..
Remember there are no 3D games, just games with a 3d perspective.
but to get a good 2D perspective then use glOrtho and draw using only x and y coordinates.
Quote: Original post by chiekku
I looked around here on the forum and didn't see anything that was helpful to me, so...

My collegue and I want to create a tile-based board game, and want to use OpenGL to create the game world. We wanted to use Direct Draw initially, since it's naturally for 2D, but since we couldn't find any help on it we decided to use OpenGL instead. I must say I'm amazed with how much support there is for it here...

I understand that OpenGL is probably best for 3D games, but we don't have enough time to spend a couple months developing a 3D game, nor do we want to. We thought OpenGL would have a wider range of capabilities than GDI, too.

I have Lesson 1 working in .net, the basic GL window and such. We really need some help in getting a game board working. We're very familiar with C++ and .net, but reletively new to game programmming. We don't really know where to start, and none of the tutorials on this site really dealt much with 2d graphics, only 3d, so I was hoping someone with experiance could fill us in on what to do next.

Much appreciated,

ChiEkku



Jump to lesson 21, you will learn the things you want. Also, I guess what you want is to develop your 2D board game in a short time. But remember, if you want to use OpenGL, you need to learn the basic knowledge of it first. There's not a shortcut.


/*----------------------------------------------------------------------------------------------------------------------------------*/Enthusiastic and wild about game development. Any opportunity would get me sink into any fantastic game-revolution era.
If you don't want to fuss with doing 2D in a 3D API, you can use SDL, which is pretty competent for 2D development; there are quite a few tutorials and people here that can help with it.

If you still want to go with OpenGL, here are some things to look into:
Orthographic projection matrices
Rendering quads
Texturing
Transformations (Scaling, Translating, Rotating)

Basically, the general idea is as follows:
(1) Use an orthographic projection matrix with left = 0, right = screen_res_x, bottom = 0, top = screen_res_y (note that with this setup, positive y points UP, which is different than traditional 2D programming). This can be accomplished with a call to glOrtho (or gluOrtho).

(2) Your MODELVIEW matrix should be the identity matrix (glLoadIdentity)

(3) All your images will be loaded as textures. NeHe has an OK tutorial for loading BMP files. Alternatively, you can get an image-loading library for other formats. FreeImage or DevIl are good, but they don't hold your hand - you'll still need to know how to get the image information to OpenGL.

(4) You then draw quads with the images (textures) mapped on those quads. Since you're in orthographic mode, you can specify the quad coordinates in terms of screen coordinates without problem. I'm fair-certain there's a NeHe tutorial on rendering simple primitives that shows how to do something with a perspective matrix as opposed to orthographic, but the concepts are the same.

(5) To make certain parts of an image transparent, you can use alpha testing or blending. Again, NeHe has a tutorial on these. This is where using an image loader comes in handy - with a .tga or .png image you can specify an alpha channel that will show up as transparent/translucent if you've got everything enabled properly.

For your purposes, you can probably get away without knowing about transformation matrices, though they're helpful. You won't need to know about lighting, extensions, model formats, or any 'advanced' stuff.

Most of this stuff will be fleshed out in the first 10 or so tutorials on NeHe. You'll also get a feel for how to grab input from the user. In the long-term, you'll gain a lot from using OpenGL over the 2D-only capabilities of SDL or DDraw, but if you just want a game fast and don't want to get bogged down in the mess of learning all the GL background, I say again to look into SDL.

Also, I mentioned NeHe a lot, but that is under no circumstances the only source of tutorials. There's even a book titled OpenGL 2D Game Programming.

Hope that helps,
--Brian
If you download the beta code announced on the top of this forum section there is a pretty nice and easy to use TGA loader in the last lesson.

This topic is closed to new replies.

Advertisement