Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (754)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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
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:

Something like:
StateManagementClass.glLineWidth(float width){
      if(currentLineWidth != width){
            currentLineWidth = width;

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);

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" 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:
public class GameTimer extends Timer{...

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

which has a run method:
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.

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:
public class GameTimer extends Thread{....

//The run method
public void run(){
   catch(InterruptedException e){

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
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.

If you look at it from the lights point of view you can see that the projection is off.

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.

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;
   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
      //Depth states
      //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
      glu.gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, cameraProjectionMatrix.m, 0);
      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);
      glu.gluPerspective(45.0f, 1.0f, 2.0f, 208.0f);
      gl.glGetFloatv(gl.GL_MODELVIEW_MATRIX, lightProjectionMatrix.m, 0);
      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);
      createObject(gl, new GLUT());
   public void display(GLAutoDrawable drawable){
      GL gl=drawable.getGL();
      GLU glu=new GLU();
      GLUT glut=new GLUT();
      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.glLoadMatrixf(lightProjectionMatrix.m, 0);
      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
      //Disable color writes, and use flat shading for speed
      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.glColorMask(true, true, true, true);
      //2nd pass - Draw from camera's point of view
      gl.glViewport(0, 0, windowWidth, windowHeight);
      gl.glLoadMatrixf(cameraProjectionMatrix.m, 0);
      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);
      DrawScene(gl, glut);
      //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);
      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.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.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.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);
      //Bind & enable shadow map texture
      gl.glBindTexture(gl.GL_TEXTURE_2D, shadowMapTexture);
      //Enable shadow comparison
      //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);
      DrawScene(gl, glut);
      //Disable textures and texgen
      //Restore other states
      //reset matrices
   public void DrawScene(GL gl, GLUT glut){
      //Draw objects
      gl.glRotatef(rot, 0.0f, 1.0f, 0.0f);
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
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:


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:

Does anyone know what I am doing wrong?
Pages: [1]
DesertCoockie (20 views)
2018-05-13 18:23:11

nelsongames (68 views)
2018-04-24 18:15:36

nelsongames (65 views)
2018-04-24 18:14:32

ivj94 (748 views)
2018-03-24 14:47:39

ivj94 (79 views)
2018-03-24 14:46:31

ivj94 (555 views)
2018-03-24 14:43:53

Solater (94 views)
2018-03-17 05:04:08

nelsongames (168 views)
2018-03-05 17:56:34

Gornova (338 views)
2018-03-02 22:15:33

buddyBro (998 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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‑
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!