Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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] 2 3 ... 5
1  Java Game APIs & Engines / JOGL Development / mouse zoom on: 2008-03-12 16:51:28
Hi,

I hope this isn't too far OT, but just looking for a pointer. I'm using a MouseInputAdapter to catch mouse buttons and now I'm trying to zoom my model with the mouse. I'd like to zoom in when the mouse rolls forwards, and zoom out when the mouse is moved backwards, but only the motions forwards and backwards.

Anyone know how to detect this?
2  Java Game APIs & Engines / JOGL Development / special fx on: 2008-02-22 05:07:16

Anyone know of any snippets of special effects one can do, or something to teach them? Something that shows how to specifically do a cool effect?

I'm looking for things that would help out my models, like ... glowing lines on selection or ... anything really. Just something to try to make them look nicer and more professional.
3  Java Game APIs & Engines / JOGL Development / jogl cameras on: 2008-01-02 20:05:32
Hi,

I'm not happy with the rotation control that I get from using an arcball implementation that took me quite a bit of time to develop.

So I'm wondering if anyone knows of other completed cameras using jogl that would provide better camera control, zooms, panning, etc... good for viewing models.

4  Java Game APIs & Engines / JOGL Development / Re: multiple viewports on: 2007-07-05 19:06:52
Is that what glScissor and glEnable(GL_SCISSOR_TEST) will do for me?

Ummm, ok, nm, think that's what I should be looking at. Thanks.
5  Java Game APIs & Engines / JOGL Development / Re: multiple viewports on: 2007-07-05 18:07:34
I assign a unique color to each element (a triangle mesh) of my model so that when my mouse hovers over the element, I can do a read pixel and do individual element selection this way which is much faster than doing picking, especially since I have so many elements on my canvas.

for each frame display()
   drawElements filled w/ unique colors
   readPixel to see where mouse is
   clear
   redrawElements as normal
   draw mouse over colors
end of frame display()

Now that I'm adding multiple viewports, the problem is that I have a glClear executed after I've ready my mouse over pixel and before I redraw my elements as normal.

So I'm wondering what I need to do so that I don't clear the entire screen (cause if I take the glClear out, I can see my drawings in each viewport fine, but of course breaks my current functionality).

Is that what glScissor and glEnable(GL_SCISSOR_TEST) will do for me?
6  Java Game APIs & Engines / JOGL Development / multiple viewports on: 2007-07-03 16:50:23
Hi,

I'm trying to make multiple viewports in a test app to see how much work it's going to take to make my real app do this. I'n this example, I've just split the screen in two and trying to get the background to draw a different color so I know what the viewports look like but it's not working. My entire screen always ends up one color. Am I not doing something right, I was trying to follow the nehe tutorial?

This is an update entry, I can get each view to draw, but only if it's the last view in my loop that get's drawn. So I'd comment out each view and just work on one to make sure that that view shows properly, then when I run them all together, it's just the last one that draws.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
   public void display(GLAutoDrawable drawable) {
      GL gl = drawable.getGL();
     
      this.glDrawable = drawable;
     
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
     
      for (int i = 0; i < 2; i++) {

         if (i == 0) {
            gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
            gl.glViewport(0, 0, (int) winWidth / 2, (int) winHeight);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity ();
            //gl.glOrtho(0, winWidth / 2, winHeight / 2, winHeight / 2, 100, -100);
        }
         else if (i == 1) {
            gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
            gl.glViewport((int) winWidth / 2, 0, (int) winWidth / 2, (int) winHeight);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity ();
            //gl.glOrtho(0, winWidth / 2, winHeight / 2, winHeight / 2, 100, -100);
        }

         gl.glMatrixMode (GL.GL_MODELVIEW);
         gl.glLoadIdentity ();
         gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
      }
   }
7  Java Game APIs & Engines / JOGL Development / ELFCLASS64 link error using solaris-sparcv9 on: 2007-02-07 18:40:44
I'm porting my application to a Sun Ultra 45 workstation (sol 10) and I'm linking with the JSR-231 1.1.0-rc2-January 23 libs.If I understand correctly, these are the 64bit libs, but my app is giving the following error on those libs ...

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: /home/me/Workspace/myApp/distrib/bin/jogl-1.1.0-rc2-solaris-sparcv9/lib/libjogl.so: ld.so.1: java: fatal: /home/me/Workspace/myApp/distrib/bin/jogl-1.1.0-rc2-solaris-sparcv9/lib/libjogl.so: wrong ELF class: ELFCLASS64
        at java.lang.ClassLoader$NativeLibrary.load(Native Method)
        at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
        at java.lang.Runtime.loadLibrary0(Runtime.java:822)
        at java.lang.System.loadLibrary(System.java:992)

Are these not the correct native libs? Am I doing something else wrong here?
8  Java Game APIs & Engines / JOGL Development / height map from lesson 34 on: 2006-07-20 17:28:04
Hey all,

I'm working on Lesson 34 of the NeHe tutorial which is about heightmaps. I'm trying to adjust it by making the terrain look how I'd like it to look so I'm adding my own data to the data file to be read in.

If I don't change the code and leave it as is from the tutorial, it works, but if I change the MAP_SIZE to be 8 (instead of 1024) and creat e an ascii file with 8 * 8 ascii characters (instead of the orig 1024 * 1024 size file), the map doesn't appear.

Anyone have an idea what I'm doing wrong?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
private static final int MAP_SIZE = 8;
private byte[] heightMap = new byte[MAP_SIZE * MAP_SIZE];

private void loadTerrainFile(String fileName, byte[] pHeightMap) throws IOException {
    FileInputStream inputStream = new FileInputStream(fileName);
   
    int bytesRead = 0;
    int bytesToRead = pHeightMap.length;
       
    while (bytesToRead > 0) {
        int read = inputStream.read(pHeightMap, bytesRead, bytesToRead);
           
        bytesRead += read;
        bytesToRead -= read;
    }

    inputStream.close();
       
    for (int i = 0; i < pHeightMap.length; i++) {
        pHeightMap[i] &= 0xFF;
    }
}


This is my data file ...

1  
aaaaaaaaccccccccggggggggllllllllrrrrrrrrssssssssttttttttzzzzzzzz


It seems like such a simple change, I don't know why it stopped working.
9  Java Game APIs & Engines / JOGL Development / Re: Remote OpenGL Performance on: 2006-06-27 22:34:51
It's just something I don't want to have to deal with. Having to budget money to buy new Exceed & 3D packages, then rearchitect my app so that it works correctly over the network.

Some desktops that I run my app on don't even render it correctly directly, not to mention indirectly. And then there are the network issues of latency and bandwidth with a dynamically generated model.

And there are even GLX calls that don't work over the network or w/o hardware acceleration.

My app just wasn't built for this so it's kind of a pain when someone says "Let's centralize our servers". Even though I make no use of this cluster in a server like fashion. My app is sort of a front end to a cluster, like a workstation console.

I was just wondering what other issues I'm going to come up against that maybe someone else has that will completely stop me in my tracks.
10  Java Game APIs & Engines / JOGL Development / Remote OpenGL Performance on: 2006-06-27 17:18:38
Hey all,

Can anyone help put in terms what sort of network connection and anything else I'm not seeing that it would take to render models w/ JOGL over a LAN from one building to another so that there is jerkiness at all in the rotation control and that it looks just as smooth as if it were running locally or what would have to be done to get to this point.

I'm working on the pro's and con's of doing this with my app and I'd have to get a package that does OpenGL extensions for my X Server (Exceed). Currently, the network is a 10/100 Ether w/ a few firewalls in between.

Any advice/comments much appreciated.

11  Java Game APIs & Engines / JOGL Development / normalization of a model? on: 2006-06-08 17:15:26
I'm trying to understand what it means to normalize a model. In working with databases, I normalize a database by making sure there is only one copy of any data in the database.

My math skills are weak and I'm trying to understand what it means to normalize a model. If it means what I think it does (scale the model so that all points are between 0 and 1), then it might help me fix my problem of centering any model my app loads and keeping the camera in one direction ... or at least, it would make doing all this much easier. Then I wouldn't have to get the min and max x, y, and z values and figure out the centrioid because  I would always know it. Does this make sense?

Can anyone elaborate on this?

12  Java Game APIs & Engines / JOGL Development / Re: setting centroid to origin on: 2006-06-01 22:32:30
Well, I was able to do something close to what you listed, but I'm not sure if it's correct cause I don't quite understand it (and it's not what's listed above, no pushing, popping).

I think I'm trying to do a fixed coordinate system. So I'm thinking of multiplication occuring in the opposite order that the code is listed (chpt. 3 of the red book). All I did was add the glTranslates you had and changed each sign.

But I don't understand why I translate to the + centroid, apply my arcball rotation, then translate back to the - centroid, which I think is back at the origin since I think this is a fixed coord system. Or would be w/o the second translate. I'm just confused. And what exactly would the push and pop do if I only draw one model? I don't have methods that draw different parts of the model in different locations like the car, wheel and lugnuts example in the redbook. I just have vertex arrays populated from coords from an input file and draw the entire thing at once.

What I have below works, but ... I don't think it's what I wanted, or if it's what was intended. I found out that by doing this, I no longer need a viewing tranformation (or point my camera at the centroid of the model since we're moving the model to the origin).

Any advice or comments on below would be great.

// my display()
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

// Projection transformation.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrtho(-winWidth, winWidth, -winHeight, winHeight, 1000, -1000);

// Reset the modelview matrix.
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();

// Modeling tranformation.
gl.glTranslatef((float) centroid.getX(), (float) centroid.getY(), (float) centroid.getZ());
gl.glScalef(getZoomFactor(), getZoomFactor(), getZoomFactor());

arcBall.getTransform().get(transf);
gl.glMultMatrixf(transf);

gl.glTranslatef((float) -centroid.getX(), (float) -centroid.getY(), (float) -centroid.getZ());

// Draw the model.
drawModel(drawable);
13  Java Game APIs & Engines / JOGL Development / setting centroid to origin on: 2006-06-01 19:36:51
Hey all,

I read in a model and render it. If the model is a square with min/max value's of ...

minX: 0 maxX: 1
minY: 0 maxY: 1
minZ: 0 maxZ: 0

... then the centroid of the model is .5, .5, 0 ... so how should I properly handle adjusting the model to the new centroid so that when it's rotated on the canvas, it's rotated around the centroid of the model and not the 0, 0 origin where it looks as if it's off balance or wobbles when it rotates?

I've got models with 10 of thousands of points and I'm wondering if I have to shift the values of the points of the model by the values of the centroid ... just seems like lots of room for error so wondering if there is a better and easier way?
14  Java Game APIs & Engines / JOGL Development / Re: FPSAnimator = Unstable Frames per second? on: 2006-05-26 21:01:45
I don't know how that book you mention uses FPSAnimator, which is an extension to Animator I'd guess, but I use Animator in my app to give a smoother effect when zooming my model in and out and it helps greatly, but depending on what the OS seems to be doing at the time, it can still be jerky and jump around on long zoom times if the cpu get's busy, or possibly for the reason you say he mentions. Something worth looking into down the road.

Just my 0.02
15  Java Game APIs & Engines / JOGL Development / Re: help positioning a model on: 2006-05-26 20:54:09
Well, that fixed the plane effect, but now when I zoom it in and out, both the front and back of the model gets cut like it's being clipped because of the position of the front and back z-axis view planes. I ran into this before and that's what led me to not scale the z-axis.

I set my glOrtho near and far to 100, -100, but the book says this shouldn't make a difference as long as they are not the same value.

So, how does the near and far planes get set so as not to clip the model when it's z value changes when zooming?

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

// Projection transformation.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();

gl.glOrtho(-winWidth, winWidth, -winHeight, winHeight, 100, -100);

// reset the modelview matrix
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();

// apply view transformation
glu.gluLookAt(0, 0, 0, centroid.getX(), centroid.getY(), centroid.getZ(), 0.0, 1.0, 0.0);

gl.glScalef(getZoomFactor(), getZoomFactor(), getZoomFactor());
arcBall.getTransform().get(transf);
gl.glMultMatrixf(transf);

// Draw the model.
{
   drawModel(drawable);
}
16  Java Game APIs & Engines / JOGL Development / Re: help positioning a model on: 2006-05-26 20:18:35
Yeah, I understand the parameters to gluLookAt(), but I don't know why that doesn't work for me.

I figure, if my model is built around the origin (which you can see by looking at the min and max x, y, and z coordinates I have above) then if I put gluLookAt's camera eyeXYZ position at ...

x = same as model centroid x
y = same as model centroid y
z = the max z value of the model

... then I get a nice alignment w/ my model and it works. I figure I'm just putting the model at the origin and backing up the camera to however large the model might be by using the the maxZ() of the model.

If I use eyeXYZ as 0, 0, 0, I get this wierd effect as if I'm looking at the side edge of a flat plane which my model is rendered on (sort of like a straight line on my canvas).

If I use eyeXYZ as 0, 0, model.getMaxZ(), then the effect is like, my model is on a flat plane and when I rotate it, it's the plane that I'm flipping around and not the model.

But I can rotate my models sphere just fine if I use the x, y, and z listed above and the model appears normally. I don't understand why though.
17  Java Game APIs & Engines / JOGL Development / help positioning a model on: 2006-05-26 19:10:04
Still wrestling w/ this problem. The problem is that when a user opens a file for display, the model from the file can be of any size and I'm trying to find a way to center it as soon as it opens up in my cavas for display.

I read in my models elements from a file and gather the minimum and maximum x, y, and z cooordinates.

minX: -4.77241516 maxX: 4.74154425
minY: -4.17707014 maxY: 4.07707024
minZ: -4.70177507 maxZ: 4.70177507

I then find the centroid of my model w/ these values and point my camera there.

Below is the code in my display(), the problem is that, when the model is loaded, it's still very far off in the distance when *I think* using the glOrtho, gluLookAt, and glScale values below should put the model almost full screen and centered on my canvas (at least it's centered). Sometimes depending on what model I open up, it's so far off in the distance, it takes for ever to zoom in on it.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
   gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

   // Projection transformation.
  gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadIdentity();

// winWidth and winHeight values are populated from the reshape() method.

   gl.glOrtho(-winWidth, winWidth, -winHeight, winHeight, 100, -100);

   // reset the modelview matrix
  gl.glColor3f(1.0f, 1.0f, 1.0f);
   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glLoadIdentity();

// Shouldn't the gluLookAt()'s eyez value below place the camera right on
// the front edge of the model? The eyez value of centroid.getMax_Z() is the
// maximum positive z value of the model.

   // Viewing transformation.
  glu.gluLookAt(centroid.getX(), centroid.getY(), centroid.getMax_Z(), centroid.getX(), centroid.getY(), centroid.getZ(), 0.0, 1.0, 0.0);

   // Modeling tranformation.

// getZoomFactor() is set at 1.0 which I think should not make a difference
// in the original size of the model when loaded.

   gl.glScalef(getZoomFactor(), getZoomFactor(), 0);

   // Apply arcball transformation.
  arcBall.getTransform().get(transf);
   gl.glMultMatrixf(transf);

   // Draw the model.
  {
      drawModel(drawable);
   }


Any help much appreciated.
18  Java Game APIs & Engines / JOGL Development / Re: how to make lines glow? on: 2006-05-17 19:37:37
Yeah, I got that, but I was wondering how or where to look up doing some neat effects, in this case, making the lines "glow".
19  Java Game APIs & Engines / JOGL Development / how to make lines glow? on: 2006-05-17 17:43:30
I have this code that basically just fills in a single triangle of my mesh when the mouse hovers over it, but it's kinda ugly. How can I make the edges of this triangle glow in and out instead of this ugly white fill.

I'm thinking I change GL.GL_FILL to GL.GL_LINE, but then, how do I get the lines to have a thick glowing effect?

1  
2  
3  
4  
5  
6  
7  
gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
gl.glColor3f(1.0f, 1.0f, 1.0f);

// ...

gl.glVertexPointer(3, GL.GL_FLOAT, 0, elementsBuffer[idx]);
gl.glDrawElements(GL.GL_TRIANGLES, 3, GL.GL_UNSIGNED_INT, indicesBuffer[idx]);

20  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-05 17:52:21
Thanks guys, this turned out incredibly nice. I've loaded models w/ several hundred thousand elements and the highlighting actually keeps up w/ the mouse pointer, translation, speedy quick!
21  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-04 22:17:21
Ugh, that worked well and now I have solid colors. I didn't think I could do that because I thought some colors (millions range, not that I would probably get that high) would get truncated by casting like that.

Now to fix the highlighting of the correct triangle. Smiley Thanks for all your help.
22  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-04 19:27:48
You have to encode your index (int) into RGB values (3 bytes, not 3 ints), then read them back as RGB (3 bytes) and decode them into your index.

So put your colors in a ByteBuffer

I am putting my colors in a ByteBuffer and my colors get incremented with the code below, they're just int value that I put there. I'm sure something here I've not got corrrect and not understanding how to code the RGB values into an index since I already have an index that goes into the indicesBuffer (an IntBuffer). I think I'm thinking that the index into the index buffer pairs up w/ the same index into the color buffer since that color was added the same time that index was add (as in our triangle loops above).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
   private int red = 0;
   private int green = 0;
   private int blue = 0;
        //...

   public void incrementColor() {
      if (blue < 255) {
         blue++;
      }
      else if (green < 255) {
         green++;
         blue = 0;
      }
      else {
         red++;
         green = 0;
         blue = 0;
      }

      return;
   }


This code is where the RGB gets decoded into an index. Does this index not come out to the same as the index's I'm assigning in the indicesBuffer? Maybe I'm just getting lucky hits.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
   public void readElementColor(GLAutoDrawable drawable) {
      GL gl = drawable.getGL();
     
      mouseBuffer.clear();
     
      gl.glReadPixels(renderer.getMouseX(), renderer.getMouseY(),
         1, 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, mouseBuffer);

      mouseBuffer.rewind();
     
      /*
       *  This turns the byte into an unsigned byte (using the sign-bit as the
       *  ordinary 8th bit of an int, 32bit).
       */

      int r = mouseBuffer.get() & 0xFF;
      int g = mouseBuffer.get() & 0xFF;
      int b = mouseBuffer.get() & 0xFF;

      // Decode the RGB to an index.
     activeTriangleIndex = (r << 16) | (g << 8) | (b << 0);
                 
      return;
   }


How exactly are you coding these colors into an index? I think if I can get past this, then I can assign my indicesBuffer the index from the RGB encoding and not use my method of just incrementing a counter for the index.

Quote from: Riven
triangle 0 [color = 0,0,0]
triangle 1 [color = 0,0,1]
triangle 2 [color = 0,0,2]
triangle 255 [color = 0,0,255]
triangle 256 [color = 0,1,0]
triangle 257 [color = 0,1,1]
triangle 258 [color = 0,1,2]
etc.
23  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-04 17:40:00
I'm not clear on what you've got there, I think maybe a typo as your first example of what I've got isn't what I've got. I only increment the colors per triangle, as I understand it, incrementing colors per vertex would change the colors for every vertex position and they all need to be the same color.

Also, when I do a readPixel, the triangle that gets highlighted jumps all over the place as if it were getting 3 random vertices from my model. That part might be too complicated to post so I'll just keep at it, but the colors I don't understand why they're not right.

I try to clarify how my colors are done here. I did change indices as you suggest and now see more colors. Before I thought all the empty triangles were just shades of black I couldn't see and my drawNormally after drawColorCoded fooled me into thinking they were being drawn. I think my next important step is getting the tri's all solid colors.

I do quesiton this line, am I understanding this correctly.
// 3 colors and we store 32 bit ints for each color w/ putInt?
ByteBuffer cBuffer = BufferUtils.newByteBuffer(3 * 4);

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
for (each triangle) { 
    int idx = 0;

    for (int i = 0; i < 3; i++) { // loop vertices of a single triangle
       // ...
       cBuffer.putInt(idx, getRed());
        triBuffer.put(idx++, (float) node.getX());

        cBuffer.putInt(idx, getGreen());
        triBuffer.put(idx++, (float) node.getY());

        cBuffer.putInt(idx, getBlue());
        triBuffer.put(idx++, (float) node.getZ());

        // by not incrementing colors inside this loop, R, G, and B stay same color.

        indicesBuffer[i].put(index++);
        indicesBuffer[i].put(index++);
        indicesBuffer[i].put(index++);
    }

colorBuffer[i].put(cBuffer); // add 9 colors per 9 vertices of this triangle
elementBuffer[i].put(triBuffer); // add 9 vertices of this triangle to array

incrementColor();
}
24  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-03 22:38:14
It's almost there. I beleive I've got this working and the performance really is much better, even though my triangles are not hightlighting properly, I can tell it functions close to what it should. I think my only problem left is that my triangles are colored wrong and I can't tell where the problem is.

From one vertex (side) of the triangle it's shaded darker/lighter and as you cross the triangle to another vertex, it gets lighter or darker. Some Triangles are all one color, but the colors of the multi-colored (shaded) triangles are all within the range that I thought I was setting my colors to.


I have a FloatBuffer triBuffer(3 * 3) per triangle that contains these coord values ...
   v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z

I have a ByteBuffer cBuffer(3 * 4) that contains int values of R, G, or B as such ...
   v1.r, v1.g, v2.b, v2.r, v2.g, v2.b, v3.r, v3.g, v3.b


Here is where I add my colors.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
// stores a single triangle.
FloatBuffer triBuffer = BufferUtils.newFloatBuffer(3 * 3);

// stores colors for a single triangle.
// 3 colors and we store 32 bit ints for each color w/ putInt?
ByteBuffer cBuffer = BufferUtils.newByteBuffer(3 * 4);

for (all triangles) {
   elementBuffer[i] = BufferUtils.newFloatBuffer(region.size() * 9);

   // 1 color = 3 bytes per triangle ((3 * 3) *3).
  colorBuffer[i] = BufferUtils.newByteBuffer((region.size() * 9) * 3);

   indicesBuffer[i] = BufferUtils.newIntBuffer(region.size() * 3);


    for (each triangle) {
   int idx = 0;

   for (int i = 0; i < 3; i++) { // loop edges of a single triangle
     cBuffer.putInt(idx, getRed());
      triBuffer.put(idx++, (float) node.getX());
   
      cBuffer.putInt(idx, getGreen());
      triBuffer.put(idx++, (float) node.getY());

      cBuffer.putInt(idx, getBlue());
      triBuffer.put(idx++, (float) node.getZ());
   }

   colorBuffer[i].put(cBuffer);
   elementBuffer[i].put(triBuffer);
   indicesBuffer[i].put(index++);

   incrementColor();
    }

    i++;
}


And here I draw my color coded triangles.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public void drawByRegions_ColorCoded(GL gl, int index, int activeId, Color color) {
   gl.glEnableClientState(GL.GL_COLOR_ARRAY);
   gl.glEnableClientState(GL.GL_VERTEX_ARRAY);

   gl.glEnable(GL.GL_CULL_FACE);
   gl.glCullFace(GL.GL_BACK);
   gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);

   vElementsBuffer[index].rewind();
   colorBuffer[index].rewind();

   gl.glColorPointer(3, GL.GL_UNSIGNED_BYTE, 0, colorBuffer[index]);
   gl.glVertexPointer(3, GL.GL_FLOAT, 0, vElementsBuffer[index]);
   gl.glDrawArrays(GL.GL_TRIANGLES, 0, vElementsBuffer[index].capacity() / 3);

   gl.glDisable(GL.GL_CULL_FACE);
   gl.glDisableClientState(GL.GL_COLOR_ARRAY);
   gl.glDisableClientState(GL.GL_VERTEX_ARRAY);

   return;
}


Does anyone see anything wrong with what I've got there. I can't tell why my colors are not a single solid color in each triangle. BTW - I just left off doing the glClear between drawing_colorCoded() and then doing a draw_Normally() within the same frame so I could see what was going on.
25  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-02 22:17:11
To be able to quickly identify which triangle was selected, it would be nice to not have FLOAT colors, but UNSIGNED_BYTE colors, to be able to work on bit-level easily later on.

UNSIGNED_BYTE didn't work for me, kept throwing IllegalArgumentExceptiosn when doing a call on glReadPixel, would fill my mouseBuffer w/ negative values. So I am using GL_BYTE which seems to work.

My hashCode idea for a key isn't panning out very well so I'm back to trying to understand this idea. Each 3 of my vertices for a triangle have the same RGB value. What I don't understand is how your using the index. Is that a String index value like "0,0,1" as a key to do a lookup? I store in a Hashtable a key w/ the object being the vertex array of 9 coord's for my triangle. I don't know why I can't understand glDrawElements().

triangle 0 [color = 0,0,0]
triangle 1 [color = 0,0,1]
triangle 2 [color = 0,0,2]
triangle 255 [color = 0,0,255]
triangle 256 [color = 0,1,0]
triangle 257 [color = 0,1,1]
triangle 258 [color = 0,1,2]
etc.

And of course I couldn't get this to work either.

Now when you read back the pixel, you'll get 3 bytes (RGB) which are quite easy to turn into the index again:
0,0,2 = (0 << 16) | (0 << Cool | (2 << 0) = 2
0,1,1 = (0 << 16) | (1 << Cool | (1 << 0) = 257
0,1,2 = (0 << 16) | (1 << Cool | (2 << 0) = 258

Can you help on this idea some more?

Other than these problems, I can see that my triangles are different colors and my mouse is reading them. It's just storing/indexing and redrawing that last element that's got me now.
26  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-02 20:40:04
Well, it's getting closer, at least now I understand what's suppose to happen. I'm just trying to implement it efficiently now.

I'm having a hard time reading the color under the pointer. For some reason, it throws exceptions like the following when I mouse over my model and I can't for anything figure why the color blue would read a -55. It does this quite a bit, throwing an exception because of blue being out of range. I've rechecked my color init method several times and the colors of my triangles RGB's are all valid between 0 - 255.

I'm betting there's a better way to do than what I've got below.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
java.lang.IllegalArgumentException: Color parameter outside of expected range: Blue
        at java.awt.Color.testColorValueRange(Color.java:285)
        at java.awt.Color.<init>(Color.java:369)
        at java.awt.Color.<init>(Color.java:344)
        at gov.nasa.jsc.renderer.Modeler.readElementColor(Modeler.java:632)
        at gov.nasa.jsc.renderer.Modeler.drawRegions(Modeler.java:185)
        at gov.nasa.jsc.renderer.Renderer.drawModel(Renderer.java:613)
        at gov.nasa.jsc.renderer.Renderer.display(Renderer.java:245)

iae, r: 0, g: 30, b: -55


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
public void readElementColor(GLAutoDrawable drawable) {
   GL gl = drawable.getGL();

   mouseBuffer.clear();

   // getMouseY() is actually winHeight() - mouseY.
  gl.glReadPixels(renderer.getMouseX(), renderer.getMouseY(), 1, 1, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, mouseBuffer);

   mouseBuffer.rewind();

   try {
      activeColor = new Color(mouseBuffer.get(0), mouseBuffer.get(1), mouseBuffer.get(2));

      System.out.println("activeColor: " + activeColor.toString() + ", hashCode: " + activeColor.hashCode());
   }
   catch (IllegalArgumentException iae) {
      iae.printStackTrace();

      System.out.println("iae, r: " + mouseBuffer.get(0) + ", g: " +   mouseBuffer.get(1) + ", b: " + mouseBuffer.get(2));
   }

   return;
}


And then I redraw the single triangle here as a last step.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
public void drawActiveElement(GL gl) {
   ActiveData elementData = null;

   if (colorMap.containsKey(activeColor.hashCode()) == false) {
      System.out.println("hashcode Not found.");
      return;
   }

   elementData = (ActiveData) colorMap.get(activeColor.hashCode());

   gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
   
   gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);
   gl.glColor3f(1.0f, 1.0f, 1.0f);

   gl.glVertexPointer(3, GL.GL_FLOAT, 0, elementData.getNodeBuffer());
   gl.glDrawArrays(GL.GL_TRIANGLES, 0, elementData.getNodeBuffer().capacity());

   gl.glDisableClientState(GL.GL_VERTEX_ARRAY);

   return;
}
27  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-01 21:50:00
Pfftt, everything is so easy for you guys!
28  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-01 18:30:18
Just a few more questions cause I don't see how going this route will solve my problems.

I don't think I understand. I have my y axis as up in my glLookAt() method and I update my mouse x & y on mouseMoved() so I should be getting something in my buffer w/ 1 in the width and height of glReadPixels. Sometimes I see values, but most of the time, the returne RGB is 0 even when I'm hovering over a triangle that was color coded.

Another question I have about using this color coded method is below. My code looks like this.

1  
2  
3  
4  
5  
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
draw_ColorCoded(...);
glReadPixels(...);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
draw_Normally(...);


I still don't see how this method works for me as I can't highlight a single element visually in the model using the last method draw_Normally(...) which looks like below (and using glDrawElements ... well, I might as well return to my old methods of bad performance).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
      gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
   
      gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE);
     
      vElementsBuffer[index].rewind();
     
      gl.glLoadName(index); // This loadName does selection on an entire group.
     gl.glVertexPointer(3, GL.GL_FLOAT, 0, vElementsBuffer[index]);
      gl.glDrawArrays(GL.GL_TRIANGLES, 0, vElementsBuffer[index].capacity() / 3);

      gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
29  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-01 16:47:02
Ok, I understood it wrong, thanks, that fixed the crash, but it still populates my mouseBuffer with 0's immediately after the glReadPixels line. So something still isn't right.

1  
2  
3  
4  
5  
6  
   mouseBuffer.rewind();

        // outputs all 0's
  while (mouseBuffer.position() < mouseBuffer.capacity()) {
      System.out.println("mouseBuffer: " + mouseBuffer.get());  
   }

30  Java Game APIs & Engines / JOGL Development / Re: color coded picking on: 2006-05-01 15:54:42
Not sure if I'm using glReadPixels, correctly, is this the correct way to call glReadPixels() when  using the mouse to select an element? For a single pixel, the size should be 3, correct? And only the x, y of the mouse gets passed into glReadPixels x, y, width, and height? Is there a specific buffer I need to read from and use glReadBuffer()?

My app crashes the vm. If I remove glReadPixels(), my app doesn't crash.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
//constructor
MyModeler {
      mouseBuffer = BufferUtils.newByteBuffer(3);
}

// called per frame rendering within display() ...

mouseBuffer.rewind();

if (renderer.getMouseX() > 0 && renderer.getMouseY() > 0) {
       gl.glReadPixels(renderer.getMouseX(), renderer.getMouseY(),
       renderer.getMouseX(), renderer.getMouseY(),
       GL.GL_RGB, GL.GL_UNSIGNED_BYTE, mouseBuffer);
}

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

Pages: [1] 2 3 ... 5
 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
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!