Jump to content
  • Advertisement
Sign in to follow this  
DanDannyPantry

OpenGL Isometricity.. if that's even a word.

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

Hello GameDev.net :)

Right now I'm working on a small project which basically involves reading in binary data from a file and then interpreting that to draw an isometric, tiled world on screen - right now I'm having issues with the creation of said tiled world. I can draw a single tile fine but I have no idea how to use maths to translate the tiles into their appropriate positions. I'm pretty new to OpenGL and wanted to pick a simple game to start with (kinda missed the mark there).
Anyway, I was wondering if you can help. What I do is, as I read in the map file, I create MapTile objects which contain the info in the file (id, flags) and then draw the tile accordingly by invoking render() on it. The code for the MapTile class is below. A few things to note: I cannot change the arguments of the render() function or the underlying interface that gives it to the MapTile class. The class is as follows:

package com.lorichon.maps;

import java.io.IOException;

import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;

import com.lorichon.controllers.ResourceLoader;
import com.lorichon.templates.RenderableObject;

/**
* Represents a Map Tile.
* @author Dan
*/
public class MapTile implements RenderableObject {
public static final int TILE_GRASS =0x00;

public static final int FLAGS_NONE =0x00;
public static final int FLAGS_WATER =0x01;

public static final String TEXTURE_TILE_GRASS = "assets/images/tile_grass.png";

private short m_tileId;
private short m_flags;

private String m_texture;

/**
* Creates a MapTile with the given ID and flags.
* @param id
* @param flags
*/
public MapTile(short id, short flags) {
m_tileId = id;
m_flags = flags;
switch(id) {
//case TILE_ISOTEST:
//m_texture = TEXTURE_TILE_ISOTEST;
// break;
case TILE_GRASS:
m_texture = TEXTURE_TILE_GRASS;
break;
default:
m_texture = TEXTURE_TILE_GRASS;
}
}

/**
* Returns true if this tile is water.
* @return
*/
public boolean isWater() {
return ((m_flags&FLAGS_WATER)==FLAGS_WATER);
}

/**
* Returns the Tile ID.
* @return
*/
public int getTileId() {
return m_tileId;
}

/**
* Returns the Texture ID to be used with OpenGL.
* @return
*/
public String getTextureName() {
return m_texture;
}

@Override
public void render() {
Texture tex = null;
try {
tex = ResourceLoader.getTexture(getTextureName());
} catch (IOException e) {} // discard exception, it'll never be null here

GL11.glPushMatrix();
{
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
// TODO how to draw in the right position?
GL11.glBegin(GL11.GL_QUADS);
{
tex.bind();
GL11.glTexCoord2f(0,0);
GL11.glVertex3f(-0.5f, 0.5f, -0.5f);
GL11.glTexCoord2f(1,0);
GL11.glVertex3f(0.5f, 0.5f, -0.5f);
GL11.glTexCoord2f(1,1);
GL11.glVertex3f(0.5f, -0.5f, -0.5f);
GL11.glTexCoord2f(0,1);
GL11.glVertex3f(-0.5f, -0.5f, -0.5f);
}
GL11.glEnd();
GL11.glDisable(GL11.GL_TEXTURE_2D);
}
GL11.glPopMatrix();
}

@Override
public void update() {
// nothing to do
}
}


In addition, could anyone tell me how I could "tint" a texture without having to create an entirely new one? :P

Thanks,
- Neglected.

Share this post


Link to post
Share on other sites
Advertisement

In addition, could anyone tell me how I could "tint" a texture without having to create an entirely new one? :P


If by 'tint' you mean adding/subtracting color to a texture, an easy was to do it using the fixed function pipeline is to change your call of:

GL11.glColor3f(1.0f, 1.0f, 1.0f);
to:

GL11.glColor3f(red, green, blue);

Where 'red', 'green', and 'blue' is a value from 0.0 to 1.0. For example, 0.0 in blue means 'no blue', 0.5 means 'half the blue that was already in the texture', and 1.0 means 'all the blue that was already in the texture'.
So your values of (1.0f, 1.0f, 1.0f) means "Of the colors in this texture, show all of the red, all of the green, and all of the blue".

So if you want your texture to look slightly more blue then it currently is, just subtract some of the red and green, and by comparison it'll look bluer.
Make sure to reset the color to glColor3f(1.0, 1.0, 1.0) before drawing an image, even if you don't want to colorize it, otherwise it'll use the colors from the previous call to glColor().

Not being a Java programmer, I don't know the answer to your other question.

Share this post


Link to post
Share on other sites

[quote name='Neglected' timestamp='1321220197' post='4883538']
In addition, could anyone tell me how I could "tint" a texture without having to create an entirely new one? :P


If by 'tint' you mean adding/subtracting color to a texture, an easy was to do it using the fixed function pipeline is to change your call of:

GL11.glColor3f(1.0f, 1.0f, 1.0f);
to:

GL11.glColor3f(red, green, blue);

Where 'red', 'green', and 'blue' is a value from 0.0 to 1.0. For example, 0.0 in blue means 'no blue', 0.5 means 'half the blue that was already in the texture', and 1.0 means 'all the blue that was already in the texture'.
So your values of (1.0f, 1.0f, 1.0f) means "Of the colors in this texture, show all of the red, all of the green, and all of the blue".

So if you want your texture to look slightly more blue then it currently is, just subtract some of the red and green, and by comparison it'll look bluer.
Make sure to reset the color to glColor3f(1.0, 1.0, 1.0) before drawing an image, even if you don't want to colorize it, otherwise it'll use the colors from the last draw.

Not being a Java programmer, I don't know the answer to your other question.
[/quote]

This actually doesn't seem to have any effect on the texture colour - I only had that glColor3f there for when I was just drawing quads and not textures, my bad :b /removes.
But thank you anyway ^^
EDIT: I stand corrected. Having it all white meant there was no effect! derp.

Share this post


Link to post
Share on other sites
Going to go ahead and bump this with a slightly different (but related) issue. I managed to get the tiles tiling, but there's a small gap between them and I also can't seem to be able to make them 3d blocks. What I'm going for is a sort of view where you have an isometric map that is one layer deep and, on the edges of the layers, you can see the underneath of the square block. :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!