Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (534)
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  
  Why is one color affecting whats already draw  (Read 1738 times)
0 Members and 1 Guest are viewing this topic.
Offline Harley Rana

Junior Member




Java games rock!


« Posted 2003-04-07 06:16:28 »

The basic problem is, im drawing some tiles ( with no color ), then draw the cursor using an outline and fill color, then the last outline color used fills the tiles.  

I don't understand why the tiles are being affected after there drawn.  Tryed all the different blendFunc modes, nothing has worked.
Thanks for any help clearing up this annoying problem! Smiley


Basic init code for ortho mode.  all there is.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
    gl.matrixMode(GL.PROJECTION);
        gl.loadIdentity();
        gl.ortho(0.0f, Display.getWidth(), Display.getHeight(), 0.0f, -100.0f, 100.0f);
        gl.matrixMode(GL.MODELVIEW);
        gl.loadIdentity();

        gl.shadeModel(GL.SMOOTH);
        gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.enable(GL.POLYGON_SMOOTH);
        gl.enable(GL.BLEND);


Main render method (simplifyed)
1  
2  
3  
4  
5  
6  
        gl.enable(GL.TEXTURE_2D);
        gl.blendFunc(GL.ONE, GL.ONE);
        gl.bindTexture(GL.TEXTURE_2D, 1);
        Tools.fillQuad2i(gl, 100, 100, 200, 200);
               
        cursor.render(gl);



The cursor render method
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
   /***********  Draw the Mouse Cursor  ****************/
        gl.color3f(0, 1, 0);
        gl.translatef(mouseX, mouseY, 0);
        Tools.fillPolygon(gl, poly);
        gl.color3f(1, 0, 0);
        Tools.drawPolygon(gl, poly);

        /***********  Draw Selection Rectangle  ****************/
        gl.translatef(-mouseX, -mouseY, 0);
        gl.blendFunc(GL.SRC_ALPHA, GL.DST_ALPHA);
        gl.disable(GL.TEXTURE_2D);
        gl.color4f(1, 1, 0, 0.2f);
        Tools.fillQuad2i(gl, dragX, dragY, dragX + dragWidth, dragY + dragHeight);
        gl.color3f(1, 0, 0);
        Tools.drawQuad2i(gl, dragX, dragY, dragX + dragWidth, dragY + dragHeight);    

Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2003-04-07 10:01:56 »

Both rendering ops have the wrong blending mode.
Tiles should be GL.ONE, GL.ZERO (ie., disable blending) as there's nothing in the background you need to blend with (I assume).

Sprites should be drawn with GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA.

DST_ALPHA refers to the alpha value already stored in the destination framebuffer, and you very likely won't have one of those, and if you did, you'd only be doing some super clever special effects with it.

Cas Smiley

Offline Harley Rana

Junior Member




Java games rock!


« Reply #2 - Posted 2003-04-08 04:51:10 »

Hey thanks for the reply, but the blending modes did not change the effect.  :-/

Its strange because i had the same thing working in perspective mode.  I was drawing the tiles and sprites in perspective, then switching into ortho mode for the cursor.  And it worked.  Same rendering code, now in all ortho mode, and it doesn't work.

Its for the josrts project.  Ive just refactored and cleand up the interfaces.  If you have some time, id really appreciate if you could check out the design and code.  Smiley

We are pretty close to having something here.  I can create a level in the editor, and see it run in gl.  Only problem is damn color blending! Cheesy

http://www.froggy.com.au/harleyrana/java/JOSRTS_0025.zip
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2003-04-08 12:05:50 »

1  
       gl.bindTexture(GL.TEXTURE_2D, 1);

is likely to cause a crash or at the very least something unexpected; you'd best fix it (in 2 places!)

1  
        gl.blendFunc(GL.ONE, GL.ONE_MINUS_SRC_ALPHA);

is still the wrong blending mode for sprites Smiley It's GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA

(Your sprites do have alpha don't they? Coz I didn't see any TGAs in that zip, only JPEGs, and they don't have an alpha channel. Otherwise we'd all be using them Smiley )

Cas Smiley

Offline Harley Rana

Junior Member




Java games rock!


« Reply #4 - Posted 2003-04-09 07:08:24 »

Hey i know i had the wrong blend modes in places, but in the 2 things that are being rendered it was as you said.

ive tryed to simplify it down to see the problem.  so everything is in one render method.

this just draws one colored quad overlapping and area of another and works find.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
    public void render()
    {
        gl.clear(GL.COLOR_BUFFER_BIT);
       
            gl.disable(GL.TEXTURE_2D);
        gl.blendFunc(GL.ONE, GL.ZERO);        
        gl.color3f(0, 1, 0);
        Tools.fillQuad2i(gl, 100, 100, 200, 200);
 
        gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
        gl.color4f(1, 0, 0, 0.1f);
        gl.disable(GL.TEXTURE_2D);
        Tools.fillQuad2i(gl, 150, 150, 400, 400);
       
        gl.swapBuffers();
    }


Then if i change it to draw a textured quad, then a colored quad, it doesn't work.  The textured quad is fully colored, when it should only be partly colored in the overlapping area.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
    public void render()
    {
        gl.clear(GL.COLOR_BUFFER_BIT);
       
            gl.enable(GL.TEXTURE_2D);
        gl.blendFunc(GL.ONE, GL.ZERO);        
        gl.bindTexture(GL.TEXTURE_2D,tileTextures[0]);
        Tools.fillQuad2i(gl, 100, 100, 200, 200);
 
        gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
        gl.color4f(1, 0, 0, 0.1f);
        gl.disable(GL.TEXTURE_2D);
        Tools.fillQuad2i(gl, 150, 150, 400, 400);
       
        gl.swapBuffers();
    }


The init code is the same as before, super simple.  I just don't see where the problem is.  Im using the correct blend modes.
Managed to keep my sanity, but it won't stay for long. Tongue

Thanks for any suggestions! Smiley


Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2003-04-09 10:57:29 »

What does Tools.fillQuad look like? The only random suggestion i'd make is try putting a gl.bindTexture(GL.TEXTURE_2D, 0) in before gl.disable(GL.TEXTURE_2D) and see if that makes a difference (shouldn't though..).

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

JGO Kernel


Medals: 342
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2003-04-09 12:09:12 »

Two things:
- You haven't reset the colour after setting it to transparent red;
- It may be that you're using a TEXENV_MODE of MODULATE in which case the entire textured quad will subsequently be modulated with transparent red.

Cas Smiley

Offline Harley Rana

Junior Member




Java games rock!


« Reply #7 - Posted 2003-04-10 00:32:55 »

Hey thanks for your help!! Smiley

Just needed gl.texEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.DECAL);
before drawing the texture. Simple Smiley

Also how do you reset the color?
its not gl.color4f(0, 0, 0, 0)?

Thanks princec! Cheesy
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.

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

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

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

Riven (24 views)
2014-07-23 20:56:16

ctomni231 (55 views)
2014-07-18 06:55:21

Zero Volt (47 views)
2014-07-17 23:47:54

danieldean (38 views)
2014-07-17 23:41:23

MustardPeter (43 views)
2014-07-16 23:30:00

Cero (59 views)
2014-07-16 00:42:17

Riven (56 views)
2014-07-14 18:02:53
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

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!