Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  GL_BACK material properties.  (Read 1415 times)
0 Members and 1 Guest are viewing this topic.
Offline dolachin

JGO n00b
*

Posts: 25


Java games rock!


« on: 2003-09-07 21:45:53 »

Hi,

Thanks for helping me figure out the previous question about lighting.

I'm still having trouble giving the back side of polygons a color different from the front side. The same sphere (with fixed lighting!) with half the triangles missing so you can see through can be found.

http://www.geocities.com/bura3no/index.htm

The relevant code is here:

     gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) );
     gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) );

     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, Color.BLACK.getComponents(null));

     gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, Color.WHITE.getComponents(null) );
     gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);

     gl.glBegin(GL.GL_TRIANGLES);
     for (int t = 0; t < myMesh.pGetNumberOfElements()/2; t++) {
       Element elem = myMesh.pGetElement(t);
       for (int v = 0; v < elem.pGetNumberOfNodes(); v++) {
         VDouble x = myMesh.pGetX(elem.pGetNode(v));
         VDouble n = normals[elem.pGetNode(v)];
         gl.glNormal3d(n.pGet(0), n.pGet(1), n.pGet(2));
         gl.glVertex3d(x.pGet(0), x.pGet(1), x.pGet(2));
       }
     }
     gl.glEnd();

   }

   gl.glEndList();
Offline cfmdobbie

JGO Wizard
****

Posts: 1257


Who, me?


« Reply #1 on: 2003-09-08 03:06:18 »

At a first glance that render loop looks fine, so make sure you're not culling the back-facing polygons and enable two-sided lighting:

1  
2  
GL.glDisable(GL.GL_CULL_FACE) ;
GL.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) ;


Hellomynameis Charlie Dobbie.
Offline dolachin

JGO n00b
*

Posts: 25


Java games rock!


« Reply #2 on: 2003-09-08 12:21:32 »

Thanks for response.

Your suggestion helped with lighting of the back side (something I did need), but not with the coloring. It's still green rather than some other color.
Games published by our own members! Go get 'em!
Offline cfmdobbie

JGO Wizard
****

Posts: 1257


Who, me?


« Reply #3 on: 2003-09-08 14:58:59 »

Well, the code you've posted looks fine, as long as Color.RED really contains a red colour.  How are the lights set up?

Not sure what to suggest... anyone else got any ideas?

Hellomynameis Charlie Dobbie.
Offline GKW

Sr. Member
**

Posts: 453


Revenge is mine!


« Reply #4 on: 2003-09-09 00:03:26 »

Need more code.
Offline dolachin

JGO n00b
*

Posts: 25


Java games rock!


« Reply #5 on: 2003-09-09 09:26:17 »

Hi,

I would very much like to post more code, but I'm not quite sure what part of my program to quote. If I have

     gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) );

and

     gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) );

right next to each other and green works but red doesn't, can you give me an idea of I might be doing wrong?

Thanks!

Pavel
Offline GKW

Sr. Member
**

Posts: 453


Revenge is mine!


« Reply #6 on: 2003-09-09 11:01:03 »

Try removing gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) ); and see what happens.  Your code looks fine but obviously something is wrong.
Offline dolachin

JGO n00b
*

Posts: 25


Java games rock!


« Reply #7 on: 2003-09-10 07:59:11 »

EVERYTHING goes black.
Offline GKW

Sr. Member
**

Posts: 453


Revenge is mine!


« Reply #8 on: 2003-09-10 09:58:17 »

Try reversing your colors, front red, back green.  If everything turns red then we know it isn't your color methods.  What kind of graphics card do you have?
Offline dolachin

JGO n00b
*

Posts: 25


Java games rock!


« Reply #9 on: 2003-09-10 11:32:09 »

Yes, it all turns red.

I have a Mobility Fire GL 9000.
Chip type: Mobility Radeon 9000 (LF).

And here's an interesting thing: When I switch to

     gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE);
     gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);

the program crashes with the following error message:

http://www.geocities.com/bura3no/error.txt


Games published by our own members! Go get 'em!
Offline GKW

Sr. Member
**

Posts: 453


Revenge is mine!


« Reply #10 on: 2003-09-10 23:15:56 »

Try making a little c app that does the same type of lighting and see if you get the same results.  If it is the same you might have found a driver bug.
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.134 seconds with 21 queries.