Nehe06 tutorial to LWJGL pre0.7 problems

Hi there !

I’ve got some problems converting the Nehe6 (Texturing tutorial) to LWJGL 0.7 and got this error message:
An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x0
Function=[Unknown.]

It seems to occur during

GL.glGenTextures(1,buf);

where buf is an IntBuffer with the TextureData.

Theres no more Sys.getDirectBufferAddress(buf), and glGenTextures() expects an IntBuffer as second argument,

what am i doing wrong ?

mbw

PS: Im new to openGL and LWJGL, and tried for hours, read all the posts etc. but nothing seems to work…
(at least nothing that i would do ;oP)

I Also had problems with that Buffer things… :wink:

Try somthing like this :


float[] specular = new float[]  {1.0f , 1.0f , 1.0f , .0f} ;
FloatBuffer glfMaterialColorBuffer = ByteBuffer.allocateDirect ( 16 ). order (ByteOrder.nativeOrder) ).asFloatBuffer () ;
      glfMaterialColorBuffer.put ( glfMaterialColor ).flip () ;

The Important is the flip of the Buffer! Also you have to say allocateDirect as shown above.

  • Jens

Hmm, still got the Error…
:o|

Here’s the


private final static 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());
            //int scratchAddress = Sys.getDirectBufferAddress(scratch);

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

              // Create A IntBuffer For Image Address In Memory            
            IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
            //int bufPtr = Sys.getDirectBufferAddress(buf);            // Get Image Address
            buf.flip();
            GL.glGenTextures(1, buf);                                                // Create Texture In OpenGL      <<<< ERROR LINE      
            GL.glBindTexture(GL.GL_TEXTURE_2D, buf.get(0));                        // Typical Texture Generation Using Data From The Image

              // Linear Filtering
            GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
              // Linear Filtering
            GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);

              // Generate The Texture
            GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, scratch);

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

It’s mostly from the tutorial at http://chman-area.tuxfamily.org/

And and the error log:

`An unexpected exception has been detected in native code outside the VM.
Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x0
Function=[Unknown.]
Library=(N/A)

NOTE: We are unable to locate the function name symbol for the error
just occurred. Please refer to release documentation for possible
reason and solutions.

Current Java thread:
at org.lwjgl.opengl.CoreGL.glGenTextures(Native Method)
at firststeps.MainWindow2.loadTexture(MainWindow2.java:85)
at firststeps.MainWindow2.execute(MainWindow2.java:45)
at firststeps.MainWindow2.main(MainWindow2.java:343)

Dynamic libraries:
0x00400000 - 0x00407000 C:\jsdk\bin\javaw.exe
0x77880000 - 0x77901000 C:\WINNT\System32\ntdll.dll
0x77DA0000 - 0x77DFB000 C:\WINNT\system32\ADVAPI32.dll
0x77E70000 - 0x77F32000 C:\WINNT\system32\KERNEL32.DLL
0x77D30000 - 0x77DA0000 C:\WINNT\system32\RPCRT4.DLL
0x77E00000 - 0x77E64000 C:\WINNT\system32\USER32.dll
0x77F40000 - 0x77F7C000 C:\WINNT\system32\GDI32.DLL
0x78000000 - 0x78046000 C:\WINNT\system32\MSVCRT.dll
0x08000000 - 0x08136000 C:\jsdk\jre\bin\client\jvm.dll
0x77540000 - 0x77571000 C:\WINNT\System32\WINMM.dll
0x10000000 - 0x10007000 C:\jsdk\jre\bin\hpi.dll
0x007E0000 - 0x007EE000 C:\jsdk\jre\bin\verify.dll
0x007F0000 - 0x00808000 C:\jsdk\jre\bin\java.dll
0x00810000 - 0x0081D000 C:\jsdk\jre\bin\zip.dll
0x18270000 - 0x1837A000 C:\jsdk\jre\bin\awt.dll
0x777F0000 - 0x7780D000 C:\WINNT\System32\WINSPOOL.DRV
0x75DF0000 - 0x75E0A000 C:\WINNT\System32\IMM32.dll
0x77A40000 - 0x77B36000 C:\WINNT\system32\ole32.dll
0x18580000 - 0x185D0000 C:\jsdk\jre\bin\fontmanager.dll
0x51000000 - 0x5104D000 C:\WINNT\System32\ddraw.dll
0x72810000 - 0x72816000 C:\WINNT\System32\DCIMAN32.dll
0x5C000000 - 0x5C0C8000 C:\WINNT\System32\D3DIM700.DLL
0x1C600000 - 0x1C607000 C:\Programme\Logitech\MouseWare\System\LgWndHk.dll
0x6E330000 - 0x6E336000 C:\WINNT\System32\INDICDLL.dll
0x1C660000 - 0x1C67E000 C:\jsdk\jre\bin\jpeg.dll
0x1C6C0000 - 0x1C70C000 C:\jsdk\jre\lib\ext\lwjgl.dll
0x5F580000 - 0x5F620000 C:\WINNT\System32\DINPUT.dll
0x693A0000 - 0x69467000 C:\WINNT\System32\OPENGL32.dll
0x6F9F0000 - 0x6FA10000 C:\WINNT\System32\GLU32.dll
0x77910000 - 0x77933000 C:\WINNT\system32\imagehlp.dll
0x72970000 - 0x7299D000 C:\WINNT\system32\DBGHELP.dll
0x68F30000 - 0x68F3B000 C:\WINNT\System32\PSAPI.DLL

Heap at VM Abort:
Heap
def new generation total 576K, used 453K [0x10010000, 0x100b0000, 0x104f0000)
eden space 512K, 75% used [0x10010000, 0x10071450, 0x10090000)
from space 64K, 99% used [0x100a0000, 0x100afff8, 0x100b0000)
to space 64K, 0% used [0x10090000, 0x10090000, 0x100a0000)
tenured generation total 1408K, used 1083K [0x104f0000, 0x10650000, 0x14010000)
the space 1408K, 76% used [0x104f0000, 0x105fec38, 0x105fee00, 0x10650000)
compacting perm gen total 4096K, used 2861K [0x14010000, 0x14410000, 0x18010000)
the space 4096K, 69% used [0x14010000, 0x142db728, 0x142db800, 0x14410000)

Local Time = Thu Aug 07 23:18:41 2003
Elapsed Time = 1

The exception above was detected in native code outside the VM

Java VM: Java HotSpot™ Client VM (1.4.2-b28 mixed mode)

`

Is no one using 0.7 out there ? :stuck_out_tongue:
(I still hope im not complaining about a too obvious problem to get an answer… but i really tried for hours read many tutorials, etc… )

An answer from the lwjgl developers would be very kind ! :slight_smile:

Thanks !

mbw

[quote]Is no one using 0.7 out there ?
[/quote]
no one is - since it hasn’t been released yet!

You are talking about pre-0.7. I have NeHe06 lying here, which works fine, though my version is for pre2-0.7 or 0.7 final or whatever we will call it :slight_smile:

I was going to post it, but some issues just came up… hang on…

Here we go, Nehe06 by chman - ported to lwjgl 0.7 (unreleased)

package Nehe06;
/**
 * Nehe06.java
 *
 * Author: Thomas Hourdel (thomas.hourdel@libertysurf.fr)
 * Date: 06/01/2003
 *
 * Port of the NeHe OpenGL Tutorial (Lesson 6: "Texture Mapping")
 * to Java using the LWJGL interface to OpenGL.
 */

/** 
 * Standard includes
 */

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;

/** Main class
 */

public final class Nehe06 {

  // GL context creation...
  static {
    try {
      Window.create("Basic Window", 50, 50, 640, 480, 16, 0, 0, 0); // Create The Opengl Context
    } catch (Exception e) {
      System.exit(1);
    }
  }

  /** Global variable declaration */
  private static boolean finished;
  private static float xrot; // X Rotation
  private static float yrot; // Y Rotation
  private static float zrot; // Z Rotation

  private static int texture; // Storage For One Texture

  /** 
   * Constructor (unused here)  
   */
  private Nehe06() {
  }

  /** 
   * Main method
   */
  public static void main(String args[]) {
    try {
      init(); // Init Opengl

      while (!finished) {
        Keyboard.poll(); // Poll The Keyboard
        mainLoop(); // Launch The Main Loop
        render(); // Render To Screen
        Window.tick();
        Window.paint(); // Swap Opengl Buffers
      }
    } catch (Throwable t) {
      t.printStackTrace();
    } finally {
      cleanup();
    }
  }

  /** 
   * Init opengl
   */
  private final static void init() throws Exception {

    texture = loadTexture("data/nehe.png");

    Keyboard.create(); // Create The Keyboard

    GL.glEnable(GL.GL_TEXTURE_2D); // Enable Texture Mapping
    GL.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading
    GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background  
    GL.glClearDepth(1.0); // Depth Buffer Setup
    GL.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing
    GL.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do

    GL.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix
    GL.glLoadIdentity(); // Reset The Projection Matrix

    // Calculate The Aspect Ratio Of The Window
    GLU.gluPerspective(
      45.0f,
      (float) Display.getWidth() / (float) Display.getHeight(),
      0.1f,
      100.0f);
    GL.glMatrixMode(GL.GL_MODELVIEW); // Select The Modelview Matrix

    // Really Nice Perspective Calculations
    GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

    //sync to monitor
    GLCaps.determineAvailableExtensions();
    if(GLCaps.WGL_EXT_swap_control) {
      GL.wglSwapIntervalEXT(1);
    }
  }

  /** 
   * Main loop
   */
  private final static void mainLoop() {
    processKeyboard(); // Get Keyboard Events
    processWindow(); // Get Window Events
  }

  /** 
   * Rendering method
   */
  private final static void render() {
    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);  // Clear Screen And Depth Buffer
    GL.glLoadIdentity();                                          // Reset The Current Modelview Matrix

    GL.glTranslatef(0.0f, 0.0f, -5.0f);

    GL.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    GL.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    GL.glRotatef(zrot, 0.0f, 0.0f, 1.0f);

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture);

    GL.glBegin(GL.GL_QUADS); {
      // Front Face
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(-1.0f, -1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(1.0f, -1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(1.0f, 1.0f, 1.0f);
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(-1.0f, 1.0f, 1.0f);
      // Back Face
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(-1.0f, -1.0f, -1.0f);
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(-1.0f, 1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(1.0f, 1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(1.0f, -1.0f, -1.0f);
      // Top Face
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(-1.0f, 1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(-1.0f, 1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(1.0f, 1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(1.0f, 1.0f, -1.0f);
      // Bottom Face
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(-1.0f, -1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(1.0f, -1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(1.0f, -1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(-1.0f, -1.0f, 1.0f);
      // Right face
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(1.0f, -1.0f, -1.0f);
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(1.0f, 1.0f, -1.0f);
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(1.0f, 1.0f, 1.0f);
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(1.0f, -1.0f, 1.0f);
      // Left Face
      GL.glTexCoord2f(0.0f, 0.0f);
      GL.glVertex3f(-1.0f, -1.0f, -1.0f);
      GL.glTexCoord2f(1.0f, 0.0f);
      GL.glVertex3f(-1.0f, -1.0f, 1.0f);
      GL.glTexCoord2f(1.0f, 1.0f);
      GL.glVertex3f(-1.0f, 1.0f, 1.0f);
      GL.glTexCoord2f(0.0f, 1.0f);
      GL.glVertex3f(-1.0f, 1.0f, -1.0f);
    }
    GL.glEnd();

    xrot += 0.3f;
    yrot += 0.2f;
    zrot += 0.4f;
  }

  /** 
   * Process keyboard events
   */
  private final static void processKeyboard() {
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
      finished = true;
  }

  /** 
   * Process window events
   */
  private final static void processWindow() {
    if (Window.isCloseRequested()) {
      finished = true;
    }
  }

  /** 
   * Cleanup
   */
  private final static void cleanup() {
    Keyboard.destroy(); // Destroy The Keyboard
    Window.destroy(); // Destroy The Opengl Context
  }

  /** 
   * Load a texture in OpenGL memory
   */

  private final static 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();
    GL.glGenTextures(buf); // Create Texture In OpenGL   

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

    // Linear Filtering
    GL.glTexParameteri(
      GL.GL_TEXTURE_2D,
      GL.GL_TEXTURE_MIN_FILTER,
      GL.GL_LINEAR);
    // Linear Filtering
    GL.glTexParameteri(
      GL.GL_TEXTURE_2D,
      GL.GL_TEXTURE_MAG_FILTER,
      GL.GL_LINEAR);

    // Generate The Texture
    GL.glTexImage2D(
      GL.GL_TEXTURE_2D,
      0,
      GL.GL_RGB,
      tex.getWidth(),
      tex.getHeight(),
      0,
      GL.GL_RGB,
      GL.GL_UNSIGNED_BYTE,
      scratch);

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

Thanks a lot ! ;D

Is there already a planned release date ?

Greets !

mbw

Yeah, as soon as possible ;D

Just a little repair of above code. Warning this code has been done in combination with my very first window so… SAVE all of your work first.

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;

import org.lwjgl.;
import org.lwjgl.opengl.
;
import org.lwjgl.input.*;

/** Main class
*/

public final class leson06l {

//static org.lwjgl.Window Window;
static GL Window=new GL(" ",24,8,16,0);
// GL context creation…
static {
try {

 Window.create(); // Create The Opengl Context 
} catch (Exception e) { 

System.exit(1);
}
}

/** Global variable declaration */
private static boolean finished;
private static float xrot; // X Rotation
private static float yrot; // Y Rotation
private static float zrot; // Z Rotation

private static int texture; // Storage For One Texture

/**

  • Constructor (unused here)
    */
    private leson06l() {
    }

/**

  • Main method
    */
    public static void main(String args[]) {
    try {
    init(); // Init Opengl

while (!finished) {
Keyboard.poll(); // Poll The Keyboard
mainLoop(); // Launch The Main Loop
render(); // Render To Screen
Window.tick();
Window.paint(); // Swap Opengl Buffers
}
} catch (Throwable t) {
t.printStackTrace();
} finally {
cleanup();
}
}

/**

  • Init opengl
    */
    private final static void init() throws Exception {
texture = loadTexture("data/nehe.png"); 

Keyboard.create(); // Create The Keyboard 

GL.glEnable(GL.GL_TEXTURE_2D); // Enable Texture Mapping 
GL.glShadeModel(GL.GL_SMOOTH); // Enable Smooth Shading 
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background   
GL.glClearDepth(1.0); // Depth Buffer Setup 
GL.glEnable(GL.GL_DEPTH_TEST); // Enables Depth Testing 
GL.glDepthFunc(GL.GL_LEQUAL); // The Type Of Depth Testing To Do 

GL.glMatrixMode(GL.GL_PROJECTION); // Select The Projection Matrix 
GL.glLoadIdentity(); // Reset The Projection Matrix 

// Calculate The Aspect Ratio Of The Window 
GLU.gluPerspective( 

45.0f,
(float) Display.getWidth() / (float) Display.getHeight(),
0.1f,
100.0f);
GL.glMatrixMode(GL.GL_MODELVIEW); // Select The Modelview Matrix

// Really Nice Perspective Calculations 
GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST); 

//sync to monitor 
//GLCaps.determineAvailableExtensions(); 
//if(GLCaps.WGL_EXT_swap_control) { 

//GL.wglSwapIntervalEXT(1);
// }
}

/**

  • Main loop
    */
    private final static void mainLoop() {
    processKeyboard(); // Get Keyboard Events
    processWindow(); // Get Window Events
    }

/**

  • Rendering method
    */
    private final static void render() {
    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
    GL.glLoadIdentity(); // Reset The Current Modelview Matrix
GL.glTranslatef(0.0f, 0.0f, -5.0f); 

GL.glRotatef(xrot, 1.0f, 0.0f, 0.0f); 
GL.glRotatef(yrot, 0.0f, 1.0f, 0.0f); 
GL.glRotatef(zrot, 0.0f, 0.0f, 1.0f); 

GL.glBindTexture(GL.GL_TEXTURE_2D, texture); 

GL.glBegin(GL.GL_QUADS); { 

// Front Face
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(-1.0f, -1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(1.0f, -1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(1.0f, 1.0f, 1.0f);
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(-1.0f, 1.0f, 1.0f);
// Back Face
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(-1.0f, -1.0f, -1.0f);
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(-1.0f, 1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(1.0f, 1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(1.0f, -1.0f, -1.0f);
// Top Face
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(-1.0f, 1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(-1.0f, 1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(1.0f, 1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(1.0f, 1.0f, -1.0f);
// Bottom Face
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(-1.0f, -1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(1.0f, -1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(1.0f, -1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(-1.0f, -1.0f, 1.0f);
// Right face
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(1.0f, -1.0f, -1.0f);
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(1.0f, 1.0f, -1.0f);
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(1.0f, 1.0f, 1.0f);
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(1.0f, -1.0f, 1.0f);
// Left Face
GL.glTexCoord2f(0.0f, 0.0f);
GL.glVertex3f(-1.0f, -1.0f, -1.0f);
GL.glTexCoord2f(1.0f, 0.0f);
GL.glVertex3f(-1.0f, -1.0f, 1.0f);
GL.glTexCoord2f(1.0f, 1.0f);
GL.glVertex3f(-1.0f, 1.0f, 1.0f);
GL.glTexCoord2f(0.0f, 1.0f);
GL.glVertex3f(-1.0f, 1.0f, -1.0f);
}
GL.glEnd();

xrot += 0.3f; 
yrot += 0.2f; 
zrot += 0.4f; 

}

/**

  • Process keyboard events
    */
    private final static void processKeyboard() {
    if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
    finished = true;
    }

/**

  • Process window events
    */
    private final static void processWindow() {
    if (Window.isCloseRequested()) {
    finished = true;
    }
    }

/**

  • Cleanup
    */
    private final static void cleanup() {
    Keyboard.destroy(); // Destroy The Keyboard
    Window.destroy(); // Destroy The Opengl Context
    }

/**

  • Load a texture in OpenGL memory
    */

private final static 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( );
GL.glGenTextures(16,buf); // Create Texture In OpenGL

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

// Linear Filtering 
GL.glTexParameteri( 

GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MIN_FILTER,
GL.GL_LINEAR);
// Linear Filtering
GL.glTexParameteri(
GL.GL_TEXTURE_2D,
GL.GL_TEXTURE_MAG_FILTER,
GL.GL_LINEAR);

// Generate The Texture 
GL.glTexImage2D( 

GL.GL_TEXTURE_2D,
0,
GL.GL_RGB,
tex.getWidth(),
tex.getHeight(),
0,
GL.GL_RGB,
GL.GL_UNSIGNED_BYTE,
scratch);

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

}
}

Now it should compile and run

YES !!! ;D

I think i understood the reasons for your changes, and can get back to learning OGL !! :wink:

THANKS !

You are welcome. This was my second (or third) program in OGL so it’s not perfect ~-^.

hi

I still have a problem with this code …

java.lang.UnsatisfiedLinkError: nglGenTextures
at org.lwjgl.opengl.CoreGL11.nglGenTextures(Native Method)
at org.lwjgl.opengl.CoreGL11.glGenTextures(Unknown Source)
at Essai1.loadTexture(Essai1.java:253)
at Essai1.init(Essai1.java:41)
at Essai1.(Essai1.java:27)
at Essai1.main(Essai1.java:34)
Exception in thread “main”

the code of loadTexture is the same as Matzon

Thanks a lot, I really love lwjgl

fx

ok, no more errors …

but my windows init correctly, but nothing happened, It just seems to be dead

i’ve tried all tut i can find about texturing, but none is working …
No error messages so i can’t find what happen

can i have your help please ?

thanks a lot
fx

What does your render loop look like?

An important line to remember is the Window.paint() call to flush the graphics pipeline and swap the buffers.

ok

it work but only when I start in fullscreen mode, and still work when i toggle to windowed mode, but not when i start in windowed mode

thanks

fx

So it works as expected in some situations? Can’t be a library loading problem then…

I’d guess there’s something fishy going on in your render logic. Can you post the core of your render loop please?

ok, this is my full code
It work only when i START in fullscreen mode …

if i do a


Window.create("Lwjgl Test",50,50,640,480,32 , 0, 16, 0);

instead of


Window.create("Lwjgl Test",32 , 0, 16, 0);

it doesn’t work…

thanks
fx


import org.lwjgl.*;
import org.lwjgl.input.*;
import org.lwjgl.opengl.*;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import javax.*;



public class Essai1 {

  public DisplayMode mode;
  private float absc;
  private long m_fPreviousTime;
  float angle;
  float angle2;
  boolean fullscreen = true;
  float xrot;
  float yrot;
  float zrot;

  int texture;

  public Essai1()
  {
    init();
    main_loop();
    //cleanup();
  }

  public static void main(String args[])
  {
    Essai1 f = new Essai1();
  }

  public void init()
  {
    try
    {
      Window.create("Lwjgl Test",32 , 0, 16, 0);
      init_GL();
      Keyboard.create();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }

  public void init_GL()
  {
    // Initialisation OpenGL
    GLCaps.determineAvailableExtensions();

    // Setup perspective mode
    GL.glMatrixMode(GL.GL_PROJECTION);
    GL.glLoadIdentity();
    GLU.gluPerspective(45.0f, (float)800 / (float)600, 1.0f, 150.0f);
    GL.glMatrixMode(GL.GL_MODELVIEW);

    // Set clear color to black
    GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    texture = loadTexture("crate.png");                              // Load the texture

    GL.glShadeModel(GL.GL_SMOOTH);                                          // Enable Smooth Shading
    GL.glEnable(GL.GL_TEXTURE_2D);                                          // Enable Texture Mapping

    GL.glClearDepth(1.0f);                                                      // Depth Buffer Setup
    GL.glEnable(GL.GL_DEPTH_TEST);                                          // Enables Depth Testing
    GL.glDepthFunc(GL.GL_LEQUAL);                                          // The Type Of Depth Testing To Do

    // Really Nice Perspective Calculations
    GL.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
  }

  public void main_loop()
  {
    while(!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && !Window.isCloseRequested())
    {

      //absc = absc + 0.01f;
      //if (absc > 1)
      //  absc = -1 ;

      for(double i=0;i<3999999;i++)
      {
      }

      // test d'un compteur de FPS
      long delta = calculateTimeDelta();
      if (delta == 0)
        delta ++;
      System.out.println(1000.f/(float)delta);


      process_keyboard();
      render();
      Window.update();
      Window.paint();
    }
  }

  public void render()
  {
    GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);      // Clear buffers
    GL.glLoadIdentity();                                                      // Load identity matrix

    GL.glTranslatef(0.0f, 0.0f,-5.0f);

    GL.glRotatef(xrot, 1.0f, 0.0f, 0.0f);
    GL.glRotatef(yrot, 0.0f, 1.0f, 0.0f);
    GL.glRotatef(zrot, 0.0f, 0.0f, 1.0f);

    GL.glBindTexture(GL.GL_TEXTURE_2D, texture);

    GL.glBegin(GL.GL_QUADS);
    // Front Face
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
    // Back Face
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
    // Top Face
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
    // Bottom Face
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
    // Right face
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f, -1.0f);
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f, -1.0f);
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f( 1.0f,  1.0f,  1.0f);
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f( 1.0f, -1.0f,  1.0f);
    // Left Face
    GL.glTexCoord2f(0.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f, -1.0f);
    GL.glTexCoord2f(1.0f, 0.0f); GL.glVertex3f(-1.0f, -1.0f,  1.0f);
    GL.glTexCoord2f(1.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f,  1.0f);
    GL.glTexCoord2f(0.0f, 1.0f); GL.glVertex3f(-1.0f,  1.0f, -1.0f);
    GL.glEnd();

    xrot += 0.9f;
    yrot += 0.5f;
    zrot += 1.2f;
  }


  public long calculateTimeDelta()
  {
    long delta;
    long currentTime = System.currentTimeMillis();
    delta = currentTime - m_fPreviousTime;
    m_fPreviousTime = currentTime;
    //System.out.println(currentTime);
    //System.out.println(delta);
    return delta;
  }


  public void process_keyboard()
  {
    Keyboard.poll();

    // Toggle fullscreen/windowed mode
    if(Keyboard.isKeyDown(Keyboard.KEY_F1))
    {
      try {
        Keyboard.destroy(); // Destroy the keyboard
        Window.destroy(); // Destroy GL window instance

        if (fullscreen) {
          //Display.resetDisplayMode();
          Window.create("Lwjgl Test", 50, 50, 800, 600, 32, 0, 16, 0);
          fullscreen = false;
        }
        else {
          //Display.setDisplayMode(mode);
          Window.create("Lwjgl Test", 32, 0, 8, 0);
          fullscreen = true;
        }

        init_GL(); // re-Init OpenGL
        Keyboard.create(); // re-Create the keyboard
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
    else if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
    {
      angle2 = angle2 + 1.2f;
    }
    else if(Keyboard.isKeyDown(Keyboard.KEY_UP))
    {
      angle2 = angle2 - 1.2f;
    }
  }


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

    // Extract The Image
    System.out.println(image.getWidth(null));
    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();
    GL.glGenTextures(buf); // Create Texture In OpenGL

    GL.glBindTexture(GL.GL_TEXTURE_2D, buf.get(0)); // Typical Texture Generation Using Data From The Image
    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, scratch);

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

Regrettably I’m unable to recreate what you’re seeing on my hardware. (This doesn’t tell us anything about where the problem is.) It comes up perfectly in windowed mode, but my hardware doesn’t cope with the context switch and bombs on a Window.update() shortly thereafter.

So until I can try it on a different machine, I can’t really suggest anything. :-/

Has anyone else given this code a try?

thanks

a least it work in fullscreen mode :wink:
maybe it’s my opengl32.dll driver …( kyro2 )

thanks for your help

bye
fx

sorry bout being a bit late - but I just switched job - so devoting my time to that atm.

Works fine on a Radeon class card. I seriously doubt the OGL implementation of the Kyro card though…