Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Re: Some general OpenGL questions on: 2009-09-22 21:32:22
OK Thanks.

So on average is some kind of state management class worth it or not?
Or do you only start to see a gain when you are working with more a complicated application.
2  Java Game APIs & Engines / JOGL Development / Some general OpenGL questions on: 2009-09-22 20:57:09
When the init method is called can I store the gl object I get there and use that everywhere else or do I have to call this
1  
gl = drawable.getGL().getGL2();

every single time, and why?

About the state of OpenGL,
how costly are things like glLineWidth, glColor, glBlendMode, glEnable/Disable?
Would it be worth it to create a class to manage the state of OpenGL eg.
instead of:
1  
glLineWidth(2);


Something like:
1  
2  
3  
4  
5  
6  
StateManagementClass.glLineWidth(float width){
      if(currentLineWidth != width){
            currentLineWidth = width;
            glLineWidth(currentLineWidth)
      }
}

With similar methods for enabling/disabling texture, blend mode, color etc.
3  Java Game APIs & Engines / JOGL Development / GLCapabilities.setNumSamples problems on: 2009-08-10 22:25:46
I recently started using jogl 2.0.

When I try to enable multi sampling with this code:
GLCapabilities glCap=new GLCapabilities(null);
glCap.setSampleBuffers(true);
glCap.setNumSamples(4);

If setNumSamples() is set to 2 or 1 then it's fine.
If it's set to 3+ it gives an error.
If it's set to 17+ there is no error but nothing happens.

I get this error:
Exception in thread "main" javax.media.opengl.GLException: Invalid result 31 from GLCapabilitiesChooser (should be between 1 and 24)

I have used this before so I know my graphics card isn't the problem and I'm guessing this has something to do with changes in version 2.0.
4  Discussions / General Discussions / Re: Disabling Alt key on: 2009-01-11 11:44:13
I've searched but I just can't find anything on this topic and I can't find anything in the documentation referring to the title bar icon menu.
5  Discussions / General Discussions / Re: Disabling Alt key on: 2009-01-07 08:04:25
Where am I supposed to put that?
I called it on the Frame I created but it still puts focus on the title bar menu.
6  Java Game APIs & Engines / JOGL Development / Re: Timers and JOGL GLCanvas.display() performance on: 2009-01-06 20:32:41
That's a good idea.
Where would I find the source?
7  Discussions / General Discussions / Disabling Alt key on: 2009-01-06 12:28:20
When the alt key is pressed focus goes to the title bar menu so the window no longer receives key events. Is there a way to disable this?
8  Java Game APIs & Engines / JOGL Development / Re: Timers and JOGL GLCanvas.display() performance on: 2009-01-05 07:59:28
Because I wanted to do it myself, I don't want to just use the Animator class without knowing what it's doing.
9  Java Game APIs & Engines / JOGL Development / Timers and JOGL GLCanvas.display() performance on: 2009-01-04 10:31:15
To run the display of a GLCanvas I used a Timer to run at about a rate of 60 frames per second which is about a 16 millisecond delay.
I created a custom class that extends Timer:
1  
public class GameTimer extends Timer{...


and a class that extends TimerTask:
1  
private class GameTimerTask extends TimerTask{...

which has a run method:
1  
public void run(){...

which calls another function which at the moment does nothing except for calling GLCanvas.display() which at the moment also does nothing, except for drawing a single square in the screen.

then:
1  
scheduleAtFixedRate(new GameTimerTask(), 0, 16);

which actually starts the timer.

It worked but then I noticed that running it chews up an entire CPU and very very slowly increases the memory usage.

So now I switched to using a thread and a loop with a sleep:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public class GameTimer extends Thread{....

//The run method
public void run(){
  while(run){
   canvas.display();
   try{
     Thread.sleep(16);
   }
   catch(InterruptedException e){
     return;
   }
 }
}


It works fine and running at about 60 fps it on has 2% CPU usage and the memory usage stays at about the same amount.

They both do exactly the same but the timer just hogs the CPU, am I doing something wrong with the timer that's causing this? or is the Timer just not that fast?

I did leave out some code to keep it as short as possible, but the basics are there.
10  Java Game APIs & Engines / JOGL Development / Re: Shadow Mapping on: 2008-10-13 12:01:05
Damn sorry, I got it fixed.
There was a problem in my matrix multiplication code. I must have looked over it a hundred times before but I went through it again and noticed that I had some values swapped around.
11  Java Game APIs & Engines / JOGL Development / Shadow Mapping on: 2008-10-13 11:05:47
I went through the tutroial at http://www.paulsprojects.net/tutorials/smt/smt.html
but I can't seem to get it working. Now I even did  just a straight copy and paste from the source code provided with the tutorial and it still doesn't work.

It almost works but there are funny artifacts everywhere.
http://img100.imageshack.us/my.php?image=cameraif2.png


If you look at it from the lights point of view you can see that the projection is off.
http://img413.imageshack.us/my.php?image=lightqc0.png

I also noticed that changing the lights near and far planes for the light projection matrix affects the shadow mapping a lot.
Changing the far plane from 8 to something like 200 seems to make the shadows a little more accurate.
http://img507.imageshack.us/my.php?image=lightcorrecteu1.png

The problem is where the matrices are calculated or where the texGen mapping is happening because the depth map is being generated correctly, at the bottom left of the images there is a picture of the lights depth map.

Heres part of the code:

   //Camera & light positions
   Vector3D cameraPosition=new Vector3D(-2.5f, 3.5f,-2.5f);
   Vector3D lightPosition=new Vector3D(2.0f, 3.0f, -2.0f, 1.0f);
   
   Vector3D white=new Vector3D(1.0f, 1.0f, 1.0f);
   Vector3D dimWhite=new Vector3D(0.2f, 0.2f, 0.2f);
   Vector3D black=new Vector3D(0.0f, 0.0f, 0.0f);
   
   Matrix4X4 lightProjectionMatrix, lightViewMatrix;
   Matrix4X4 cameraProjectionMatrix, cameraViewMatrix;
   
   public int rot=0;
   
   //Size of shadow map
   final int shadowMapSize=512;
   
   //Textures
   int shadowMapTexture;
   
   //Display lists for objects
   int spheresList=-1, torusList=-1, baseList=-1;
   
   public void init(GLAutoDrawable drawable){
      GL gl=drawable.getGL();
      GLU glu=new GLU();
      
      //Load identity modelview
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glLoadIdentity();
      
      
      //Depth states
      gl.glClearDepth(1.0f);
      gl.glDepthFunc(gl.GL_LEQUAL);
      gl.glEnable(gl.GL_DEPTH_TEST);
      
      gl.glEnable(gl.GL_CULL_FACE);
      
      
      //Create the shadow map texture
      gl.glBindTexture(gl.GL_TEXTURE_2D, shadowMapTexture);
      gl.glTexImage2D(   gl.GL_TEXTURE_2D, 0, gl.GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0,
            gl.GL_DEPTH_COMPONENT, gl.GL_UNSIGNED_BYTE, null);
      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.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP);
      gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP);
      
      //Calculate & save matrices
      gl.glPushMatrix();
      
      gl.glLoadIdentity();
      glu.gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, cameraProjectionMatrix.m, 0);
      
      gl.glLoadIdentity();
      glu.gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
         0.0f, 0.0f, 0.0f,
         0.0f, 1.0f, 0.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, cameraViewMatrix.m, 0);
      
      gl.glLoadIdentity();
      glu.gluPerspective(45.0f, 1.0f, 2.0f, 208.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, lightProjectionMatrix.m, 0);
      
      gl.glLoadIdentity();
      glu.gluLookAt(   lightPosition.x, lightPosition.y, lightPosition.z,
         0.0f, 0.0f, 0.0f,
         0.0f, 1.0f, 0.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, lightViewMatrix.m, 0);
      
      gl.glPopMatrix();
      
      createObject(gl, new GLUT());
   }
   
   public void display(GLAutoDrawable drawable){
      GL gl=drawable.getGL();
      GLU glu=new GLU();
      GLUT glut=new GLUT();
      
      cameraPosition=lightPosition.copy();
      gl.glLoadIdentity();
      glu.gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
         0.0f, 0.0f, 0.0f,
         0.0f, 1.0f, 0.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, cameraViewMatrix.m, 0);
      
      //First pass - from light's point of view
      gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT);
      
      gl.glMatrixMode(gl.GL_PROJECTION);
      gl.glLoadMatrixf(lightProjectionMatrix.m, 0);
      
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glLoadMatrixf(lightViewMatrix.m, 0);
      
      //Use viewport the same size as the shadow map
      gl.glViewport(0, 0, shadowMapSize, shadowMapSize);
      
      //Draw back faces into the shadow map
      gl.glCullFace(gl.GL_FRONT);
      
      //Disable color writes, and use flat shading for speed
      gl.glShadeModel(gl.GL_FLAT);
      gl.glColorMask(false, false, false, false);
      
      //Draw the scene
      DrawScene(gl, glut);
      
      //Read the depth buffer into the shadow map texture
      gl.glBindTexture(gl.GL_TEXTURE_2D, shadowMapTexture);
      gl.glCopyTexSubImage2D(gl.GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
      
      //restore states
      gl.glCullFace(gl.GL_BACK);
      gl.glShadeModel(gl.GL_SMOOTH);
      gl.glColorMask(true, true, true, true);
      
      
      
      
      //2nd pass - Draw from camera's point of view
      gl.glClear(gl.GL_DEPTH_BUFFER_BIT);
      
      gl.glViewport(0, 0, windowWidth, windowHeight);
      gl.glLoadIdentity();
      gl.glMatrixMode(gl.GL_PROJECTION);
      gl.glLoadIdentity();
      gl.glLoadMatrixf(cameraProjectionMatrix.m, 0);
      
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glLoadIdentity();
      gl.glLoadMatrixf(cameraViewMatrix.m, 0);
      
      //Use dim light to represent shadowed areas
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_POSITION, lightPosition.toFloatArray(), 0);
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_AMBIENT, dimWhite.toFloatArray(), 0);
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, dimWhite.toFloatArray(), 0);
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, black.toFloatArray(), 0);
      gl.glEnable(gl.GL_LIGHT1);
      gl.glEnable(gl.GL_LIGHTING);
      
      gl.glPushMatrix();
      
      DrawScene(gl, glut);
      
      gl.glPopMatrix();
      
      //3rd pass
      //Draw with bright light
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_DIFFUSE, white.toFloatArray(), 0);
      gl.glLightfv(gl.GL_LIGHT1, gl.GL_SPECULAR, white.toFloatArray(), 0);
      
      //Calculate texture matrix for projection
      //This matrix takes us from eye space to the light's clip space
      //It is postmultiplied by the inverse of the current view matrix when specifying texgen
      Matrix4X4 biasMatrix=new Matrix4X4(0.5f, 0.0f, 0.0f, 0.0f,
                     0.0f, 0.5f, 0.0f, 0.0f,
                     0.0f, 0.0f, 0.5f, 0.0f,
                     0.5f, 0.5f, 0.5f, 1.0f);   //bias from [-1, 1] to [0, 1]
      //Matrix4X4 textureMatrix=biasMatrix.multiply(lightProjectionMatrix);
      //textureMatrix=textureMatrix.multiply(lightViewMatrix);
      Matrix4X4 textureMatrix=biasMatrix.multiply(lightProjectionMatrix.multiply(lightViewMatrix));
      
      //Set up texture coordinate generation.
      gl.glTexGeni(gl.GL_S, gl.GL_TEXTURE_GEN_MODE, gl.GL_EYE_LINEAR);
      gl.glTexGenfv(gl.GL_S, gl.GL_EYE_PLANE, textureMatrix.getRow(0), 0);
      gl.glEnable(gl.GL_TEXTURE_GEN_S);
      
      gl.glTexGeni(gl.GL_T, gl.GL_TEXTURE_GEN_MODE, gl.GL_EYE_LINEAR);
      gl.glTexGenfv(gl.GL_T, gl.GL_EYE_PLANE, textureMatrix.getRow(1), 0);
      gl.glEnable(gl.GL_TEXTURE_GEN_T);
      
      gl.glTexGeni(gl.GL_R, gl.GL_TEXTURE_GEN_MODE, gl.GL_EYE_LINEAR);
      gl.glTexGenfv(gl.GL_R, gl.GL_EYE_PLANE, textureMatrix.getRow(2), 0);
      gl.glEnable(gl.GL_TEXTURE_GEN_R);
      
      gl.glTexGeni(gl.GL_Q, gl.GL_TEXTURE_GEN_MODE, gl.GL_EYE_LINEAR);
      gl.glTexGenfv(gl.GL_Q, gl.GL_EYE_PLANE, textureMatrix.getRow(3), 0);
      gl.glEnable(gl.GL_TEXTURE_GEN_Q);
      
      //Bind & enable shadow map texture
      gl.glBindTexture(gl.GL_TEXTURE_2D, shadowMapTexture);
      gl.glEnable(gl.GL_TEXTURE_2D);
      
      //Enable shadow comparison
      gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_COMPARE_MODE_ARB, gl.GL_COMPARE_R_TO_TEXTURE);
      
      //Shadow comparison should be true (ie not in shadow) if r<=texture
      gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_COMPARE_FUNC_ARB, gl.GL_LEQUAL);
      
      //Shadow comparison should generate an INTENSITY result
      gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_DEPTH_TEXTURE_MODE_ARB, gl.GL_INTENSITY);
      
      //Set alpha test to discard false comparisons
      gl.glAlphaFunc(gl.GL_GEQUAL, 0.99f);
      gl.glEnable(gl.GL_ALPHA_TEST);
      
      DrawScene(gl, glut);
      
      //Disable textures and texgen
      gl.glDisable(gl.GL_TEXTURE_2D);
      
      gl.glDisable(gl.GL_TEXTURE_GEN_S);
      gl.glDisable(gl.GL_TEXTURE_GEN_T);
      gl.glDisable(gl.GL_TEXTURE_GEN_R);
      gl.glDisable(gl.GL_TEXTURE_GEN_Q);
      
      //Restore other states
      gl.glDisable(gl.GL_LIGHTING);
      gl.glDisable(gl.GL_ALPHA_TEST);
      
      //reset matrices
      gl.glMatrixMode(gl.GL_PROJECTION);
      gl.glPopMatrix();
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glPopMatrix();
      
      gl.glFinish();
      
   }
   
   public void DrawScene(GL gl, GLUT glut){
      //Draw objects
      gl.glPushMatrix();
      gl.glCallList(baseList);
      gl.glPopMatrix();
      gl.glPushMatrix();
      gl.glCallList(torusList);
      gl.glPopMatrix();
      
      gl.glPushMatrix();
      gl.glRotatef(rot, 0.0f, 1.0f, 0.0f);
      gl.glCallList(spheresList);
      gl.glPopMatrix();
   }
   
}
12  Discussions / General Discussions / Re: How does fbo work? on: 2008-10-06 07:41:43
I have but I just can't seem to understand it or get it to work.
Could anyone point me to a good tutorial or maybe some sample code which demonstrates
how you could setup fbos and then draw and read to them by setting
glDrawBuffer and glReadBuffer.
13  Discussions / General Discussions / How does fbo work? on: 2008-10-05 23:17:05
I would like to render some objects offscreen to a fbo and then use copypixels to copy from the fbo to the front buffer.
Is this possible?
Can I render normally to a fbo?
Something like
glDrawBuffer(FBO);
14  Game Development / Newbie & Debugging Questions / Problems installing and using JOGL on: 2008-10-01 13:40:11
I'm having problems getting jogl to work.
I've followed all the instructions but just can't get it to work.
I'm using windows xp home and downloaded jogl-1.1.1-windows-i586 which I placed in My Documents\java\jogl.
I set the classpath and path environment variables to point to the jogl directory.

So first I import everything with:

import javax.media.opengl.*;

then I have something like this:

public static void main(String[] args){
   GLCanvas canvas = new GLCanvas();
}

It compiles without any problems but when I run it I get this error:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/media/opengl/GLCanvas
Caused by: java.lang.ClassNotFoundException: javax.media.opengl.GLCanvas
...
...

Does anyone know what I am doing wrong?
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (26 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (95 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42

Longarmx (39 views)
2014-09-07 01:12:14

Longarmx (45 views)
2014-09-07 01:11:22

Longarmx (41 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!