Java-Gaming.org 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   
Pages: [1]
  ignore  |  Print  
  NeHe 08: works, but changing current color alpha has no effect on transarency  (Read 1482 times)
0 Members and 1 Guest are viewing this topic.
Offline keith_myers

Senior Newbie





« Posted 2006-03-09 19: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
Offline SluX

Junior Devvie





« Reply #1 - Posted 2006-03-10 14:13:00 »

Well if u spent hours debuging,then consider how many it would take any1 here without code Wink

"Intelligence is the most beautiful gift and the greatest temptation which one life can receive from the gods."Me Cheesy
Play strategic football
Offline keith_myers

Senior Newbie





« Reply #2 - Posted 2006-03-10 19: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);
   }
}
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 57
Projects: 11


Monkey for a head


« Reply #3 - Posted 2006-03-10 19:50:32 »

Vertex colours have no effect if lighting is enabled, instead material colours are used instead. You can use colour material to have the vertex colours specify the material colours instead. IIRC you need something like:

1  
2  
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline keith_myers

Senior Newbie





« Reply #4 - Posted 2006-03-10 21: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);
Pages: [1]
  ignore  |  Print  
 
 

 
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 (595 views)
2018-03-24 14:43:53

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

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

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

buddyBro (1038 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
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!