Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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  
  drawing 2D image  (Read 1166 times)
0 Members and 1 Guest are viewing this topic.
Offline divxdede

Junior Duke





« Posted 2012-05-17 07:33:48 »

So, i have a question.

I want be able to draw an image with alpha on the screen.
I want the color fusion to be done with the current color on the buffer.

For this i fo 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  
    // enable SRC_OVER
    glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

    // bind a translucent color for our quad
    glColor4f(0f,0f,0f,0f);

    // draw our quad with the alpha image
    glEnable(GL.GL_TEXTURE_2D );
    glBindTexture(GL.GL_TEXTURE_2D, ctx.getTexture().getTextureId() );
    glBegin(GL.GL_QUADS);
     
    glTexCoord2f( textureBounds[0].getX() , textureBounds[0].getY() );
    glVertex2f ( x , y );
     
    glTexCoord2f( textureBounds[1].getX() , textureBounds[1].getY() );
    glVertex2f( x + img.getWidth() , y );
     
    glTexCoord2f( textureBounds[2].getX() , textureBounds[2].getY() );
    glVertex2f( x + img.getWidth() , y + img.getHeight() );
     
    glTexCoord2f( textureBounds[3].getX() , textureBounds[3].getY() );
    glVertex2f(x, y + img.getHeight() );
     
   glEnd();
   glBindTexture( GL.GL_TEXTURE_2D , 0 );

   // restore previous color


With this sequence, it draw nothing. It le me thinks that the translucent color disable the quad to be visible ?

PS: with an opaque image, it's the same....  i don't undestand what it do....
Offline pitbuller
« Reply #1 - Posted 2012-05-17 09:48:24 »

Do you enable blending?
Offline divxdede

Junior Duke





« Reply #2 - Posted 2012-05-17 10:19:53 »

yes using glEnable( GL.GL_BLEND );
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline divxdede

Junior Duke





« Reply #3 - Posted 2012-05-17 10:51:32 »

If i change my translucent color by WHITE glColor4f(1f,1f,1f,1f); it works.
But i don't understant why... ? have you an idea ? it has somethings that trick me.
Offline davedes
« Reply #4 - Posted 2012-05-17 14:03:33 »

If the vertex colors are transparent black (r=0f, g=0f, b=0f, a=0f), then your image will not show. Setting the alpha component to zero would be the equivalent of rendering an image with 0% opacity (i.e. invisible). Setting it to 1.0 would be the equivalent of 100% opacity (i.e. fully visible).

Also, the red, green and blue components should be white (1.0f) unless you want to tint your image a different colour.

By this logic, if you wanted to render your image with 50% opacity:
1  
2  
glColor4f(1f, 1f, 1f, 0.5f);
//now place vertices...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

theagentd (19 views)
2014-10-25 15:46:29

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (46 views)
2014-10-16 15:22:06

Norakomi (34 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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