Problems loading texture and a question about sprites

I’m trying to use TextureIO.newTexture(…) to read a texture so I can use it for some sprites but whenever I call the function I get a null pointer returned, not matter what set of parameters I feed to it. Does anyone know why it’s happening or how to fix it?

Also, should I be using GL_QUADS with textures on them for my sprites, or should I be using something like glDrawPixels? I’ve used OpenGL in C++ for a class, but I’ve never done anything like make a game. I’ve mostly used it for making 3D stuff. If I were to use glDrawPixels, how would I get them in a format that the function can use?

I don’t have time for a lengthy answer but this sounds like what you’re looking for.

http://www.opengl.org/registry/specs/ARB/point_sprite.txt

I skimmed the link you posted, but I don’t think its quite what I’m looking for.

And it doesn’t mention anything about how to load the textures either =/

Can you paste in the call where you are trying to create the texture?

Here’s a quick example of how to output the texture once you successfully created a Texture object:


Texture myTex = TextureIO.newTexture( ... );
myTex.bind();
gl.glBegin(GL.GL_QUADS);
            gl.glTexCoord2f(0, 0); gl.glVertex2f(0, 0);
            gl.glTexCoord2f(0, 1); gl.glVertex2f(1, 0);
            gl.glTexCoord2f(1, 1); gl.glVertex2f(1, 1);
            gl.glTexCoord2f(1, 0); gl.glVertex2f(0, 1);
gl.glEnd();
gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

Now you may have to fiddle with the texture coordinates to get the proper orientation of the image, I didn’t really bother to look at the order. I would highly suggest you read up on how OpenGL texturing works before going any further. Then once you figure out the basics you can try implementing the techniques that the previous poster mentioned

I’m not on my home computer, but I remember what I did. I’ve tried a few different things. I’m not worried abou binding the texture or anything between the glBegin or glEnd, the problem is that the texture I try to generate is always a null pointer.

Texture myTex1 = TextureIO.newTexture(myBufImg, true); // returns null
Texture myTex2 = TextureIO.newTexture(new File(filename), true); // returns null

I’ve tried a few different things, but I can’t get the texture loaded. If I could do that I’m sure I could get it drawn to the screen.

Just in case you haven’t perused this yet
http://download.java.net/media/jogl/builds/nightly/javadoc_public/

Are you getting any exceptions when you try to create the texture? I usually get an IOException if I give a bad file path or if the image formatted isn’t supported. I took a look at the source for TextureIO and Texture, and there are lots of exceptions being thrown and lots of checks for null… so if you aren’t getting any exceptions thrown and you are just getting null every time, that suggests something more sinister is happening.

Could you post a simple program or something that just loads up a texture from a file and displays it? I’ve tried reading through the API and looking for tutorials, but I’m having no luck. I keep getting unrelated exceptions whenever I try the Jogl ports of NeHe’s tutorials.

So lets say you have a project with a package like org.MyProject

Inside the package MyProject you have a class called TextureLoading, and an image called image.jpg


import com.sun.opengl.util.TextureIO;
import com.sun.opengl.util.Texture;
...

public class TextureLoading {
  private Texture tex;
  ...

  public void init(GLAutoDrawable drawable) {
    ...
    try {
      tex = TextureIO.newTexture(
         getClass().getClassLoader().getResourceAsStream("org/MyProject/image.jpg"), false, TextureIO.JPG
      );
    }
    catch(IOException e) {
      e.printStackTrace();
    }
   ...
  }

}

Also, make sure you have textures enabled?

Thanks, I think I have it now. It was a combination of problems, which is why whenever I fixed one thing it still didn’t work. I’ll be able to get them loaded now.

<3