Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
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: Java2D/JOGL Interoperability Demo on: 2006-03-30 21:34:56
I have the newest JOGL and Java 6 beta yet I get very low frame rates with this code.  Could someone point out the error of my ways?  The same code runs very fast when the AWT widget is used in place of the Swing.

   //=====( Begin constructor )=================================================

   /**
    * Get the JFrame, rendering canvas, and rendering thread set up.
    */

   public GL_Game_Core()
   {
      // Create GLCanvas, and do setup involving it
//      GLCanvas canvas = new GLCanvas(new GLCapabilities());
      GLJPanel canvas = new GLJPanel(new GLCapabilities());

      canvas.addGLEventListener(this);
      getContentPane().add(canvas);
      animator = new Animator(canvas);

      // Make adjustments to the JFrame
      setUndecorated(true);
      setResizable(false);

      // Go into fullscreen mode
      DisplayMode displayMode = new DisplayMode(
         SCREEN_WIDTH,
         SCREEN_HEIGHT,
         BITS_PER_PIXEL,
         REFRESH_RATE);
      GraphicsEnvironment environment =
         GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice device = environment.getDefaultScreenDevice();
      device.setFullScreenWindow(this);
      device.setDisplayMode(displayMode);

      // Start the rendering thread
      setVisible(true);
      animator.start();
      canvas.requestFocus();
   }

   //=====( End Constructor )===================================================
   /////////////////////////////////////////////////////////////////////////////
   //=====( Begin init() )======================================================

   /**
    * Do all one-time-only setup operations.
    */

   public void init(GLAutoDrawable drawable)
   {
      // Get current GL and GLU
      GL gl = drawable.getGL();

      // Create the GLUT object
      glut = new GLUT();
      glu  = new GLU();

      // Get TextureManager instance
      textureManager = TextureManager.getInstance(gl, glu);

      // Enable basic OpenGL functions
      gl.glEnable(GL.GL_LIGHTING);
      gl.glEnable(GL.GL_DEPTH_TEST);
      gl.glEnable(GL.GL_CULL_FACE);

      // Set state variables
      gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
      gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
      gl.glClearDepth(1.0f);
      gl.glDepthFunc(GL.GL_LEQUAL);
      gl.glShadeModel(GL.GL_SMOOTH);
      gl.glCullFace(GL.GL_BACK);

      // Create and setup camera instance
      camera = new Camera(baseCameraMoveRate,
                          baseCameraRotationRate,
                          eyeX, eyeY, eyeZ,
                          centerX, centerY, centerZ,
                          upX, upY, upZ);

      // Create object to manage key and mouse events
      inputManager = new InputManager((Component)drawable);
      
      // Get rid of the cursor
      inputManager.setCursor(InputManager.INVISIBLE_CURSOR);
      
      // Create the LightManager
      lightManager = LightManager.getInstance(gl, camera);

      // Wire up key and mouse commands
      createGameActions();

      // Do initialization that is specific to the extending class
      initGameSpecificCode(gl, glu);

      // The game is about to start, so get the start time for time-based
      // movement and frames per second calculations
      currentTime = System.nanoTime();
      startTime   = currentTime;
   }

   //=====( End init() )========================================================

Thanks much,

Keith
2  Java Game APIs & Engines / JOGL Development / Re: NeHe 08: works, but changing current color alpha has no effect on transarency on: 2006-03-10 22:10:39
Thanks much Orangy Tang.  This works perfectly now thanks to your suggestion and changing the blend func from the one on NeHe08 to the one shown here.  I'm still getting the texel color becoming the polygon color though on untextured polys and text.  My guess was that after the applied fix the color of those polys would have been light gray.  Just for information sake, the only texture in the little demo is solid green with a black arrow for orientation, and the non-textured polygons are the same color green (sans the arrow of course).  Again, thanks much for the good advice.

Keith


      // Draw translucent objects
      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
      gl.glEnable(GL.GL_COLOR_MATERIAL);
      gl.glColorMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT_AND_DIFFUSE);
      gl.glColor4f(1f, 1f, 1f, .9f);
      gl.glDepthMask(false);
      
      gl.glBegin(GL.GL_QUADS);
3  Java Game APIs & Engines / JOGL Development / Re: NeHe 08: works, but changing current color alpha has no effect on transarency on: 2006-03-10 20:41:43
I didn't post any code because I figured this was a common and known problem.  It seemed like a bit much to just throw this up here, but I suppose it may be the only way to get the help needed.  As mentioned, the two quads draw fine, and show transparency, but the transparency is not influenced by the values of GL_COLOR4f() as the tutorial describes.  A possibly related problem is that some random texel from the bound texture is becoming the current color, so any text ends up that color as does any quad NOT textured.   I had to remove a good deal of code for this to fit in the post, so many unrelated methods are simply missing and quite a bit of seemingly unrelated code was removed from inside of the methods that ARE shown.  If it turns out that no answer is available from this, I will be happy to put the whole thing up.

Any help appreciated!


public class GL_Game_Core extends JFrame implements GLEventListener
{
   public void init(GLAutoDrawable drawable)
   {
      // Get current GL and GLU
      GL gl = drawable.getGL();

      // Create the GLUT object
      glut = new GLUT();
      glu  = new GLU();

      // Get TextureManager instance
      textureManager = TextureManager.getInstance(gl, glu);

      // Enable basic OpenGL functions
      gl.glEnable(GL.GL_LIGHTING);
      gl.glEnable(GL.GL_DEPTH_TEST);
      gl.glEnable(GL.GL_CULL_FACE);

      // Set state variables
      gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
      gl.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
      gl.glClearDepth(1.0f);
      gl.glDepthFunc(GL.GL_LEQUAL);
      gl.glShadeModel(GL.GL_SMOOTH);
      gl.glCullFace(GL.GL_BACK);
   }

   public void display(GLAutoDrawable drawable)
   {
      // Get current GL and GLU
      GL gl = drawable.getGL();

      // Clear drawing surface and the z buffer
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

      // Clear the modelview matrix giving all transformations a fresh start
      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();

      // Force all remaining operations through the pipeline.
      gl.glFlush();
   }

   private void initGameSpecificCode(GL gl, GLU glu)
   {      
      // Create textures
      try
      {
         textureManager.createManagedTexture("translucentTexture",
                                             "green.png",
                                             GL.GL_TEXTURE_2D,
                                             GL.GL_RGB,
                                             GL.GL_RGB,
                                             GL.GL_LINEAR,
                                             GL.GL_LINEAR,
                                             false,
                                             true);
      }
      catch(IOException ioe)
      {   

      }
   }

   // Extending class places additional 3D drawing code here
   private void draw3D(GL gl, GLU glu)
   {   
      gl.glEnable(GL.GL_TEXTURE_2D);
      textureManager.bindTexture("translucentTexture");
      
      // Draw translucent objects
      gl.glEnable(GL.GL_BLEND);
      gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
      gl.glDepthMask(false);
      gl.glColor4f(1f, 1f, 1f, .8f);
      
      gl.glBegin(GL.GL_QUADS);
            
         gl.glNormal3f( 0f,  1f, 0f);
         gl.glTexCoord2f(0f, 1f); gl.glVertex3f(-1f,  1f, 1f);
         gl.glTexCoord2f(0f, 0f); gl.glVertex3f(-1f, -1f, 1f);
         gl.glTexCoord2f(1f, 0f); gl.glVertex3f( 1f, -1f, 1f);
         gl.glTexCoord2f(1f, 1f); gl.glVertex3f( 1f,  1f, 1f);
         
         
         gl.glNormal3f( 0f,  1f, 0f);
         gl.glTexCoord2f(0f, 1f); gl.glVertex3f(-1f,  1f, 2f);
         gl.glTexCoord2f(0f, 0f); gl.glVertex3f(-1f, -1f, 2f);
         gl.glTexCoord2f(1f, 0f); gl.glVertex3f( 1f, -1f, 2f);
         gl.glTexCoord2f(1f, 1f); gl.glVertex3f( 1f,  1f, 2f);
            
      gl.glEnd();
      
      gl.glDisable(GL.GL_TEXTURE_2D);
      gl.glDepthMask(true);
      gl.glDisable(GL.GL_BLEND);
   }
}
4  Java Game APIs & Engines / JOGL Development / NeHe 08: works, but changing current color alpha has no effect on transarency on: 2006-03-09 20:47:18
Well, the title pretty much sums it up: the code seems correct in my program but altering the alpha value of the current color does nothing toward setting transparency of the textures.  Any ideas?  Surely its something simple, but I've spent several hours and can't find it.

Thanks,

Keith
5  Java Game APIs & Engines / JOGL Development / Re: viewing translucent polygons from behind (color is too dark) on: 2006-03-08 03:13:19
That was one of the things I tried, unfortunately.  It supplied a partial fix by at least allowing you to SEE the poly from the back, but then the lighting was too dark because, of course, the light source was shining on the front face.  I'm imagining a stained glass window with the sun shining on it... it's well lit from the front AND back. 
6  Java Game APIs & Engines / JOGL Development / viewing translucent polygons from behind (color is too dark) on: 2006-03-07 21:16:14
I've been messing around for several hours trying to get a simple translucent polygon to look correct from both sides.  It's fine from the front, and blending works as expected.  In fact if I put several in a row the 'add' correctly.  If I move the camera around to the back and look toward the light source through the polygons they are dark for obvious reasons.

So, how might I convince the polygon to behave as you would expect a pane of glass to behave in a window?  It seems as long as I have lighting enabled when I draw the poly it will never look right, but if lighting is off you cant see it at all...

I can put some code up if needed, and thanks for any input.

Keith
7  Java Game APIs & Engines / JOGL Development / Re: Easy way to get more than MAX_LIGHTS? on: 2006-02-16 18:33:59
I spent a bit of time looking on the Web and found some descriptions of "virtualized lighting" techniques, so I believe I'll try to code a Light class and LightManager to implement the idea.  If I get something that seems to work OK in the near future I'll put the code up here in case someone else might find it useful / interesting.
8  Java Game APIs & Engines / JOGL Development / Re: Easy way to get more than MAX_LIGHTS? on: 2006-02-14 22:20:45
I was just curious to tell you the truth.  I had made a little test scene with more than 8 lights (sort of like torches) at various locations and just wondered how this was handled since it SEEMS like professional games have quite a few on at one time sometimes.  I was simply hoping for an easy / cheap way to go, but it obviously isn't going to happen.

Thanks for the answers, I certainly appreciate it.

Keith
9  Java Game APIs & Engines / JOGL Development / Easy way to get more than MAX_LIGHTS? on: 2006-02-14 19:37:13
I just read an article on how to use shaders to achieve this, but that's way beyond my current level of knowledge. Is there a relatively easy way to achieve this using the basic calls in the Red Book?
10  Java Game APIs & Engines / JOGL Development / Display lists or VBO? on: 2006-01-31 15:05:57
I can't seem to get a definite answer on exactly when to use display list, when to use vertex arrays/VBOs.  First off, can a VBO do everything a vertex array can do only faster?  Second, if I have static geometry will a display list give similar results to the fastest alternative?  From my reading the display list effectively removes all method call overhead, does all calculations ahead of time, and stores the results directly on the video card.  This sounds pretty good. 

Thanks,

Keith
11  Java Game APIs & Engines / JOGL Development / glNormal3f(float, float, float) no longer supported? on: 2006-01-15 16:57:58
This method still shows up in my code completion window, but seems to only work when I use the version that takes a FloatBuffer.  Is this the case?

Thanks
12  Java Game APIs & Engines / JOGL Development / Re: Pros and cons of a Polygon Class? on: 2006-01-03 18:43:19
Based on the two replies, I believe the whole way I was thinking about this is wrong.  Let's use this scenario: an empty scene except for 100 cubes.  Each of the cubes is identical, having having red, green, blue, yellow, orange, and purple sides.

I have been thinking that the current color would be set to red, render all red, set current color to blue, render all blue...

But the Mesh class sounds as if each Entity attempts to optimize rendering within the context of its own self without regard to the rest of the scene.  Is this the case?

Thanks,

Keith
13  Java Game APIs & Engines / JOGL Development / Re: Pros and cons of a Polygon Class? on: 2005-12-31 16:43:41
The first question I have regards sorting: with the proposed Polygon class its easy for me to see that the objects would be sorted based on some field (say z depth) and then rendered.  Without it, how will I carry this out?  All I can picture now is a bunch of numbers in the buffer without any direct tie to which polygon they came from.  My next thought would be that they need to be sorted before being placed in the buffer, but, again, without the Polygon class I can't don't have an idea there either.

If you know a book that would answer all these questions, please let me know.
14  Java Game APIs & Engines / JOGL Development / Re: Pros and cons of a Polygon Class? on: 2005-12-27 22:52:21
Thanks for the response Vorak... I'll look at this over the next few days and see if I can get something off the ground.  If not, I'll ask another question.
15  Java Game APIs & Engines / JOGL Development / Pros and cons of a Polygon Class? on: 2005-12-27 21:40:40
After making my way through the first several chapters of the red book, and reading posts on this board related to depth sorting and state management it seems each individual polygon needs to be an object so that its fields could be used to determine which texture it currently uses, its z depth, etc.  This seemed especially important after reading a post saying that all objects in the scene need to be broken down into the individual polygons so they may be sorted on various features related to those polygons.

I think the idea of a Polygon Class sounds good from an OO standpoint, but what about memory consumption?  At the very least there would be the vertex data, and once many thousands of Polys were on the screen it doesn't seem feasable.

So, could someone give me the pros and cons of this idea?  If the concept is viable, and used in the real world, what type of info would be stored at the instance level?  At the class level (that is, if static members would make any sense here)?  Are there any 'tricks' that a relative noob could grasp that might get around the memory consumption?

I have read a bit about old Quake 1 style rendering being done in a Java fashion, and the book proposed this type Polygon class, so it's clear it can be done, but SHOULD it be?

Thanks,

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

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (24 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

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

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

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
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!