LWJGL
May 20, 2013, 23:03:03 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: LWJGL 2.5 and Texture load for 2d isometric  (Read 5391 times)
Twixly
Newbie
*
Posts: 5


« on: August 25, 2010, 02:27:25 »

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.
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 1112



« Reply #1 on: August 25, 2010, 02:52:00 »

Make sure you have enabled textures in opengl.

GL11.glEnable(GL11.GL_TEXTURE_2D);
Logged
Twixly
Newbie
*
Posts: 5


« Reply #2 on: August 25, 2010, 04:58:58 »

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

Code:
        // 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 :

Code:
        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();

Logged
Evil-Devil
Prolific Timewaster
****
Posts: 298



WWW
« Reply #3 on: August 25, 2010, 05: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
Logged
Twixly
Newbie
*
Posts: 5


« Reply #4 on: August 25, 2010, 06:49:24 »

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 Smiley
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 Sad
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 1112



« Reply #5 on: August 25, 2010, 06:52:01 »

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.
Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #6 on: August 25, 2010, 22:55:32 »

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

Twixly
Newbie
*
Posts: 5


« Reply #7 on: August 26, 2010, 04:19:27 »

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 Smiley
Logged
kappa
Administrator
Nerdus Imperius
*****
Posts: 1112



« Reply #8 on: August 26, 2010, 04:27:13 »

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 Smiley

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.
Logged
broumbroum
Prolific Timewaster
****
Posts: 316



WWW
« Reply #9 on: August 26, 2010, 05:07:25 »

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

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

Code:
        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().
Logged

Sf3JSwing project, code repo (Apache License) -  http://www.sourceforge.net/p/sf3jswing
Sf3jswing Project Forum - http://apps.sourceforge.net/phpbb/sf3jswing/
Estraven
Regular nerd
**
Posts: 53


« Reply #10 on: September 09, 2010, 22:06:35 »

Hey,

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

Estraven
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!