LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: pn__ on October 28, 2004, 14:24:23

Title: texture creating problem
Post by: pn__ on October 28, 2004, 14:24:23
hi

im trying to load a texture like it is described in the nehe tutorial.

all i get is:
java.lang.UnsatisfiedLinkError: nglGenTextures
   at org.lwjgl.opengl.GL11.nglGenTextures(Native Method)
   at org.lwjgl.opengl.GL11.glGenTextures(Unknown Source)
...

everything else (untextured stuff) works really nice...
do i need another library or something ?

thank you
Title: texture creating problem
Post by: Chman on October 28, 2004, 15:25:50
Can you post the texture loading stuff to see what's wrong ?
:)

Chman
Title: texture creating problem
Post by: pn__ on October 28, 2004, 15:33:16
hi
here is the sourcecode...



public int loadTexture(String path)
{
   
   Image image = (new javax.swing.ImageIcon(path)).getImage();

       // Exctract The Image
       BufferedImage tex = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR);
       Graphics2D g = (Graphics2D) tex.getGraphics();
       g.drawImage(image, null, null);
       g.dispose();

       // Flip Image
       AffineTransform tx = AffineTransform.getScaleInstance(1, -1);
       tx.translate(0, -image.getHeight(null));
       AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR);
       tex = op.filter(tex, null);

       // Put Image In Memory
       ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight());

       byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null);
       scratch.clear();
       scratch.put(data);
       scratch.rewind();

       // Create A IntBuffer For Image Address In Memory
       IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
       //GL11.glGenTextures(buf); // Create Texture In OpenGL


       GL11.glGenTextures(buf); // HERE IT CRASHES


       GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
       // Typical Texture Generation Using Data From The Image

       // Linear Filtering
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
       // Linear Filtering
       GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
       // Generate The Texture
       GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tex.getWidth(),
                         tex.getHeight(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);

       return buf.get(0); // Return Image Address In Memory
}


[/code]
Title: texture creating problem
Post by: Chman on October 28, 2004, 17:14:18
Hum that's strange, I don't see any problem in this code... Which version of LWJGL are you using ? What's your video card ?

Chman

PS: Just one thing, are you loading the texture before starting the rendering loop or during the loop ? Texture loading in OpenGL should be made in initilization code (so just before starting the rendering loop)...
Title: texture creating problem
Post by: CaptainJester on October 28, 2004, 19:07:33
Also make sure in your init code that you call GL11.glEnable(GL11.GL_TEXTURE_2D);

when you want to use the texture are you calling GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
Title: texture creating problem
Post by: pn__ on October 28, 2004, 19:28:35
hey

i just got it, i was trying to do this before initializing display and opengl, which is a bit stupid :))

anyway, thank you for helping