LWJGL 2.5 and Texture load for 2d isometric

Started by Twixly, August 25, 2010, 09:27:25

Previous topic - Next topic

Twixly

Hello, I am trying to switch over to LWJGL since it has neat OpenGL functions obviously, I am doing a 2d game but want to be able to implement 3d effects on top. I found a nice tutorial how to set up a 2d scene (http://basic4gl.wikispaces.com/2D+Drawing+in+OpenGL).
But now I am having problems understanding how to load and display textures, I can draw a simple white square, however I cannot get a Texture on it. I have tried various tutorials, but I have to ask. Is there no built in way to load and display Textures? It seems like such a basic thing. Yet I seem to find lots of people asking the same thing?

I tried the Devil tutorial on Wiki, but I suppose Devil is no longer supported in 2.5 or something since it seem to be missing some lib/jar file?
There is the TGA tutorial I have not tried, I am using PNG files as of now, is there a differance?

If there is no native to LWJGL way to simply loadTexture function, what would you suggest I use?
I tried something called slick.util, seems to work but still wont display any texture (no errors though).

I tried to use the code as shown in my above 2d tutorial linke under "Putting it all together". It works fine and draws all the difference shapes. I used the following to try and put a texture on a shape : Slick.util load texture

I just put the load and then texture.bind(); before I stated my glBegin().

Maybe it's my knowledge of OpenGL (which is none) that gets in the way, something I am missing. Maybe just drawing a 2d shape like this isnt actually making a "surface" which I can put texture on or something? well any advice would be much appritiated.

kappa

Make sure you have enabled textures in opengl.

GL11.glEnable(GL11.GL_TEXTURE_2D);

Twixly

I do that, here's the GL stuff I use :

        // Setup a 2D projection
        GL11.glMatrixMode (GL11.GL_PROJECTION);
        GL11.glLoadIdentity ();
        GL11.glOrtho (0, targetWidth, targetHeight, 0, 0, 1);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glMatrixMode (GL11.GL_MODELVIEW);
        GL11.glLoadIdentity();
        // Displacement trick for exact pixelization
        GL11.glTranslatef(0.375f, 0.375f, 0);


Here's the load + render :

        Texture tex = TextureLoader.getTexture("PNG", new FileInputStream("mydata/image.png"));
       
        boolean gameRunning = true;

        while (gameRunning) {
            // perform game logic updates here

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
            // render using OpenGL
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex3f(0,0,pos);
            GL11.glVertex3f(100,0,pos);
            GL11.glVertex3f(100,100,pos);
            GL11.glVertex3f(0,100,pos);
            GL11.glEnd();

            // now tell the screen to update
            Display.update();

Evil-Devil

Well there is no built in for loading texture in opengl. You might use Slick for your whole texturing stuff as it comes with a lot of supported formats and you don't have to reinvent the wheel.

If you're interested in the wheel, you might take a look at the tga texture loading tutorial: http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/textures/tga

Twixly

Quote from: Evil-Devil on August 25, 2010, 12:22:05
Well there is no built in for loading texture in opengl. You might use Slick for your whole texturing stuff as it comes with a lot of supported formats and you don't have to reinvent the wheel.

If you're interested in the wheel, you might take a look at the tga texture loading tutorial: http://lwjgl.org/wiki/doku.php/lwjgl/tutorials/textures/tga

No, I'll make do with Slick - if I can get it to work :)
All I get from my above code is the simple white square top left, from what I can tell 0,0 -> 100,100 as expected. Alas, no texture but no errors either.
When I try to check stuff in Texture (my tex in code) I can access and see that width and height etc is in, so it seems loaded allright.

edit:
I also try the slick :
tex.bind();
instead, neither works, just a white square :(

kappa

Just a note to avoid confusion, there are two libraries, one is Slick2D (which is a full 2d library) the other is Slick-Util (a standalone subset of Slick2D for loading Textures and Sounds, can be used with any 2d/3d lwjgl project).

hopefully this post should help.

Matthias

You can also use TWL's PNGDecoder (also available as stand alone JAR). It is very easy to use: example

Twixly

javalwjgl :
Yes I am using the slick.util standalone. I did follow that thread. Just can't understand what's going wrong.

Matthias :
I can try, but as far as I can tell I am loading the image successfully, it's the actuall display of it that wont work.

I am guessing I do something wrong in my above code when doing all the GL11.stuff to set it up, since I do not know alot about that.
My second code segment is the render loop, maybe I forget to call some function or something?

As I said, after load I can see that the image (Texture class) has the right width, height and there's data in it. Bah I am baffled.
I really suggest LWJGL devs. to add some easy way to load/display basic images, since it's a game engine after all it's pretty vital :)

kappa

Quote from: Twixly on August 26, 2010, 11:19:27
I really suggest LWJGL devs. to add some easy way to load/display basic images, since it's a game engine after all it's pretty vital :)

its not a game engine, its suppose to be a bare bone layer that just give you direct access to opengl/openal.

The rest should be up to the user, you could consider using a proper engine like jMonkeyEngine or Ardor3D, or even Slick2D (from which you can access OpenGL directly for the 3d effects).

I suggest you look at the source code for Slick-Utils, it contains 'tests' which are examples on slick-util usage and how to load images. Once those work then work your way back to your own code.

broumbroum

Quote from: Twixly on August 25, 2010, 11:58:58
I do that, here's the GL stuff I use :

(...)
Here's the load + render :

        Texture tex = TextureLoader.getTexture("PNG", new FileInputStream("mydata/image.png"));
       
        boolean gameRunning = true;

        while (gameRunning) {
            // perform game logic updates here

            GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID());
            // render using OpenGL
            GL11.glBegin(GL11.GL_QUADS);
            GL11.glVertex3f(0,0,pos);
            GL11.glVertex3f(100,0,pos);
            GL11.glVertex3f(100,100,pos);
            GL11.glVertex3f(0,100,pos);
            GL11.glEnd();

            // now tell the screen to update
            Display.update();

you miss glTexCoord() before each glvertex() and maybe glBindTexture(gl_texture_2d,0) after glEnd().

Estraven

Hey,

By the way, even if it's not the topic here, you might want to stop using old direct rendering stuff... ;)

Estraven