OpenGL Isometric Tile Engine

Stalin55
Unregistered
 
Post: #1
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?
Quote this message in a reply
Stalin55
Unregistered
 
Post: #2
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)?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
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.
Quote this message in a reply
Stalin55
Unregistered
 
Post: #5
How do do transparent textures where the white pixels are transparent?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
You don't; you do transparent textures where the transparent pixels are transparent.
Quote this message in a reply
Stalin55
Unregistered
 
Post: #7
How exactly do I do that?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
Using alpha testing and/or blending.
Quote this message in a reply
Stalin55
Unregistered
 
Post: #9
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.
Quote this message in a reply
Moderator
Posts: 522
Joined: 2002.04
Post: #10
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
Quote this message in a reply
Stalin55
Unregistered
 
Post: #11
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).
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #12
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?
Quote this message in a reply
Member
Posts: 161
Joined: 2005.07
Post: #13
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #14
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.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #15
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?
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  BYOND Isometric DMdude 0 2,087 Dec 29, 2009 10:11 PM
Last Post: DMdude
  Isometric tile question swiftd 3 3,366 Aug 19, 2009 05:25 AM
Last Post: swiftd
  Multithreaded OpenGL Engine Technote OneSadCookie 8 4,763 Nov 13, 2006 01:27 PM
Last Post: OneSadCookie
  Isometric people skrew 8 5,943 Feb 15, 2006 01:33 AM
Last Post: skrew
  Scene-Level OpenGL Engine Needed robsteely 6 3,890 Jan 26, 2003 06:02 AM
Last Post: kelvin