Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  OpenGL glColor3f interfering with textures?  (Read 529 times)
0 Members and 1 Guest are viewing this topic.
Offline JonnyGingerKid

Senior Newbie


Exp: 1 year



« Posted 2014-04-06 20:57:42 »

Hey so my problem is pretty short and simple. I'm kind of new to OpenGL and I noticed that when I call glColor3f when I'm about to draw lines or a quad, it sets all of the textures that I rendered to be that color as well. I tried using glPushMatrix() and glPopMatrix() before I called glColor3f(1, 0, 0) but it still changed all of my textures to be red and black... Sad (I load my textures with SlickUtil btw) Any way around this? Thanks.
Offline Drenius
« Reply #1 - Posted 2014-04-06 20:59:32 »

glPopMatrix() after the color  and vertex calls.
All sets will be reset to what they were when you called glPushMatrix() when you call glPopMatrix().
Or is there any further problem?
Offline JonnyGingerKid

Senior Newbie


Exp: 1 year



« Reply #2 - Posted 2014-04-07 06:30:29 »

You mean like this?

glPushMatrix();
   glBegin(GL_LINES);
      glColor3f(1, 0, 0);
      glVertex2f(100, 100);
      glVertex2f(200, 200);
   glEnd();
glPopMatrix();

Because that's what I was using before and my textures are still red and black... Maybe glClearColor would work? But how would I do that?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline StumpyStrust
« Reply #3 - Posted 2014-04-07 06:49:03 »

Really? OpenGL is state based. So when you say glColor4f(0,0,0,0) all fixed function drawing will use the current bound color which is (0,0,0,0).

If you want to "clear" the color after drawing something, just call glColor4f(1,1,1,1).


Offline Drenius
« Reply #4 - Posted 2014-04-07 19:06:40 »

- but if you are not using transparency, just stick with       glColor3f(1, 1, 1);
Offline JonnyGingerKid

Senior Newbie


Exp: 1 year



« Reply #5 - Posted 2014-04-07 21:54:43 »

Really? OpenGL is state based. So when you say glColor4f(0,0,0,0) all fixed function drawing will use the current bound color which is (0,0,0,0).

If you want to "clear" the color after drawing something, just call glColor4f(1,1,1,1).



Whatever man. All I know is I call glColor4f(1, 1, 1, 1) before I render each texture and my textures and my lines can all get along now for some reason. But now, all my quads are all topsy turvy and won't even render when I give them a color. Why does OpenGL have to be so confuzzling?  Cranky
Offline StumpyStrust
« Reply #6 - Posted 2014-04-07 22:01:39 »

I think it is the fixed function pipeline that is confusing because we are so object oriented today.

Basically, all calls to GL11 etc are state based. IE if you say glColor(1,1,1,1), everything that requires a color will pull from that state. So any time you want to change the color for something you need to change glColor. This is the same for all GL11 stuff.

I recommend creating some sort of batching using VBOs. It is not nearly as bad as it seems but you basically fill up arrays with data and send it to the GPU.

Offline Drenius
« Reply #7 - Posted 2014-04-07 22:01:47 »

If I remember right, the last 1 in glColor4f is alpha, which means transparency here.
A value of 1 would be fully transparent. You could either change it to 0 or just use glColor3f.
Calling a color change for everything is probably not the best way though.
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #8 - Posted 2014-04-08 00:52:48 »

1 is actually full opaque and 0 is completely transparent IIRC.

Offline StumpyStrust
« Reply #9 - Posted 2014-04-08 02:19:11 »

Actually, Drenuis that is the best way when using fixed function.

If you want a different color for each corner of a quad, you would call glColor4f four times.

If you call color4f with (1,1,1,0) and then call color3f with (1,1,1) the alpha still is 0, so for clarity you may as well use glcolor4f.

opiop65 is right.


Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Drenius
« Reply #10 - Posted 2014-04-08 02:25:45 »

- just ment calling a color change even if there is none is not necessarily good. But normally it does not even make a real difference so ya...

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 743
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2014-04-09 09:50:13 »

If you call color4f with (1,1,1,0) and then call color3f with (1,1,1) the alpha still is 0
Not true. glColor3f sets alpha to 1

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Pages: [1]
  ignore  |  Print  
 
 

 

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 (26 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (55 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!