iDevGames Forums
OpenGL Isometric Tile Engine - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL Isometric Tile Engine (/thread-3989.html)

Pages: 1 2


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 05:27 PM

First of all, I'm not very experienced with OpenGL but I have enough basic knowledge of it to find my way around and figure out how to do stuff. Secondly I have a lot of experience programming 2d isometric tile engines. I am looking into the possibility of creating a 2d isometric engine(much like Diablo) with OpenGl, but I'm not quite sure which is the most practical and efficient way to go about doing it. Can anyone give me a somewhat detailed description of the best for creating a 2d isometric tile engine with OpenGL?


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 06:36 PM

I was just fooling with texturing quads (each quad and texture map is 80x40 pixels) using pre-rendered isometric tile bitmaps (2:1 ratio) as seen in a mock bitmap image below...

00008800000
00888888000
00008800000

....and I guess because the texture image isn't perfectly square OpenGL is not letting me apply the texture, is there some way around this (or perhaps this is the wrong method all together)?


OpenGL Isometric Tile Engine - OneSadCookie - Aug 15, 2006 06:36 PM

Put your tiles in textures and draw them on quads. I'd be tempted to actually use a 3D world and an isometric projection rather than do everything with bitmaps, but you could go either way. If you go the bitmap route, you may need to turn on alpha testing to get things to draw correctly.


OpenGL Isometric Tile Engine - OneSadCookie - Aug 15, 2006 06:38 PM

Textures in OpenGL must have power-of-two dimensions (eg. 128x64), unless you use the (ARB|EXT|NV)_texture_rectangle extension. The extension is available on all hardware newer than the Rage 128.


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 07:20 PM

How do do transparent textures where the white pixels are transparent?


OpenGL Isometric Tile Engine - OneSadCookie - Aug 15, 2006 07:27 PM

You don't; you do transparent textures where the transparent pixels are transparent.


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 07:29 PM

How exactly do I do that?


OpenGL Isometric Tile Engine - OneSadCookie - Aug 15, 2006 07:33 PM

Using alpha testing and/or blending.


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 09:00 PM

I fooled around using all different combinations of glBlend() and I can't seem to find a way to make part of my textures transparent. I'm using tgas and I tried removing the background layer in photoshop because I read that tga supports alpha channels, and that still didn't work.


OpenGL Isometric Tile Engine - aarku - Aug 15, 2006 09:20 PM

You want glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Then draw from farthest to nearest.

You could use the OpenGL Profiler application to confirm that your textures are right as your game is running.

-Jon


OpenGL Isometric Tile Engine - Stalin55 - Aug 15, 2006 09:57 PM

aarku Wrote:You want glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Then draw from farthest to nearest.

Thats exactly the function that I used and is doesn't work.

To be more specific about the program, I have one bitmap texture containing a 2:1 isometric tile image and I texture it to a 128x64 quad on the screen. Then texture another identical quad (over top quarter first quad).


OpenGL Isometric Tile Engine - OneSadCookie - Aug 15, 2006 09:58 PM

The dimensions of the quad are irrelevant; the dimensions of the texture image are what matters.

What precise behavior are you seeing, and what precise code are you using?


OpenGL Isometric Tile Engine - imikedaman - Aug 15, 2006 10:42 PM

Am I the only one who realizes blending the alpha components doesn't work if the source image doesn't have an alpha channel? The guy said multiple times he wants the white pixels to be transparent, which implies the image doesn't already have transparency.

Anyway, when binding your texture you need to have an alpha channel, or 4 bytes per pixel. I'm assuming your image is just RGB right now, but you could probably get away with something like this:
Code:
char * data;
int width, height;
// read in RGB image here
// let's assume data now contains the RGB pixels at 3 bytes per pixel
// and width and height contain the width and height of the image

int size = width * height;
char data2[size * 4];
int m, n;

for (n = 0; n < size; n++) {
  m = n * 4;
  data2[m] = data[m]; data2[m+1] = data[m+1]; data2[m+2] = data[m+2]; // copy the RGB values
  if (data[m] == data[m+1] == data[m+2] == 1.0) // if pixel = white
    data2[m+3] = 1.0; // make transparent
  else
    data2[m+3] = 0.0; // make opaque
}

// bind texture as RGBA instead of RGB
The code is untested and could probably stand to be optimized, but that's one way of making perfectly white pixels transparent. However, you're much better off just giving the source image an alpha channel in an image editor and using a texture loader that supports transparency.


OpenGL Isometric Tile Engine - OneSadCookie - Aug 16, 2006 01:38 AM

I said earlier that he should use transparent pixels, and he is using tga, so there's no problem with the image format not supporting it.

So not only is your code broken, and ugly as sin, but it's completely unnecessary.


OpenGL Isometric Tile Engine - arekkusu - Aug 16, 2006 07:51 AM

imikedaman Wrote:Am I the only one who realizes blending the alpha components doesn't work if the source image doesn't have an alpha channel?

Sure it does. In the fixed function pipeline, textures are modulated with the current vertex color by default. So regardless of what the texture alpha is, if you glColor4f(1, 1, 1, 0.5) before drawing you should see some blending.



But seriously, why is loading a translucent texture so hard for everyone? I've seen this same thread a dozen times now.

Do we need to write "draw a green triangle" and "draw a texture mapped triangle" sample code?