LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: mac on July 29, 2003, 21:04:27

Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on July 29, 2003, 21:04:27
Hi,

and again im a bit confused  :shock:
I dowloaded some of the Nehe Ports avaible on :

http://chman-area.tuxfamily.org/links.html

To be exakt i tired to launch the Lesson 06 - Simple Rotate Cube

So, good, i setup the Project in JBuilder 9 (i know that IDE very good)

All needed jars were found, but the Lesson seems far from Compileable ?

As example (static init):

   static
{
try
{
 // Create The Display Mode
int mode = -1;
DisplayMode[] modes = Display.getAvailableDisplayModes();
for(int i = 0; i < modes.length; i ++)
{
if(modes[i].width == 800 &&
  modes[i].height == 600 &&
  modes[i].bpp >= 16)
{
mode = i;
break;
}
}

[b]Display.create(modes[i]);[/b] }
catch(Exception e)
{
System.exit(1);
}
}




Is not Compileable, the reason for this seems that the Method has
changed into Display.setDisplayMode(Displaymode).
And if i go down the Source Code from Lesson 6 more such things come
to Daylight eg.
In Class Gl im unable to find a Method called GL.swapBuffers()Im using 0.7 of lwjgl is it the right one for these Examples ?

thx,
Jens
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: Matzon on July 29, 2003, 22:29:31
is the version of lwjgl you're using pre-0.7 or the one in CVS at the moment?

if it's the one in cvs, you should be able to do it like so:

/**
* 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 variables...
 public static final GLWindow glw =
   new GLWindow("Basic Window", 50, 50, 640, 480, 16, 0, 0, 0);

 // GL context creation...
 static {
   try {
     glw.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 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
       glw.tick();
       glw.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 (glw.isCloseRequested()) {
     finished = true;
   }
 }

 /**
  * Cleanup
  */
 private final static void cleanup() {
   Keyboard.destroy(); // Destroy The Keyboard
   glw.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);

   // Create A IntBuffer For Image Address In Memory  
   IntBuffer buf =
     ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
   GL.glGenTextures(1, 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
 }
}
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on July 29, 2003, 22:35:45
Thx 4 fast Answer, i love that  :D

Im using the actual avaible version 0.7 from http://www.lwjgl.org/

I will try it now.

- Jens
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on July 29, 2003, 23:05:27
Hmm,

it must work if i could get the latest Sources...
I found the GLWindow Class in the repository, this one of two
i cant find while try to Compile the sourcees

Im new to CVS, what name "modulename" will the CVS Client have to Checkout the whole Project ?

- Jens
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: Matzon on July 30, 2003, 05:39:11
I'll send you a working copy - but it will have to wait some 8 hours, since I need to get to work...
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on July 30, 2003, 10:37:48
Fine,

i found out were to find the Modulenames in CVS  :roll:
Hope that i can make the first test with LWJGL for my PlugIn
Interface for my Player Project. :D
Actually i have designed some Interfaces and Services for
PlugIns to use.

- thx
Jens
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: Matzon on July 31, 2003, 21:54:32
just following up... you need binaries from me ?
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on July 31, 2003, 22:50:47
Yep,

i was trying Smart CVS (Webstart Version)
and was unable to checkout the project, i fyou
could post also some "were to checkout the modules" ?
I have tried this with module name "lwjgl" , but the source never
saw my harddisk  :cry:

If possible send the binaries to this mail address :

java-code@mac-systems.de

thx,
Jens
Title: Which version of lwjgl needed to Compile the simple Examples
Post by: mac on August 02, 2003, 12:51:40
Thx 4 Binaries.

Have done the first simple things.
Seems to be very stable and performs very well.


- Jens