Sign in to follow this  

OpenGL MultiTexture Problem

This topic is 2434 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys,

I have got the problem that I want to blend two textures together before mapping them onto a poly. The blending works fine, but when I try to to use glColor(0,1,0,1) to tint the resulting texture in this case green nothing happens. I think it must something have to do with the environment sate or something like that. probably it's just one more line of code but I just can't find the problem. Here is the code snippet:

[code]
// Texture Stage 0
// Simply output texture0 for stage 0.


glActiveTextureARB( GL_TEXTURE0_ARB );
glEnable( text01.getTextureData().textureTarget );
glBindTexture( text01.getTextureData().textureTarget, text01.getTextureData().textureID );

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE );

// Texture Stage 1
// Perform a linear interpolation between the output of stage 0
// (i.e texture0) and texture1 and use the RGB portion of the vertex's
// color to mix the two.

glActiveTextureARB( GL_TEXTURE1_ARB );
glEnable( text02.getTextureData().textureTarget );
glBindTexture( text02.getTextureData().textureTarget, text02.getTextureData().textureID );

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR );

glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_CONSTANT );
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_CONSTANT );

//------------------------
float mycolor[4];
mycolor[0]=mycolor[1]=mycolor[2]=0.0; //RGB doesn't matter since it's not used
mycolor[3]=blend; //Set the blend factor with this

glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, mycolor);
// << maybe here is something like another glTexEnvi(...) neccessary
glColor4f( 0, 1, 0, 1 ); // tying to tint the resulting mixed texture green but it's not working
[/code]

Thank you very much for your help. I am new to OpenGL but I need this code to work for an assignment at my university.

Raymond

Share this post


Link to post
Share on other sites
[url="http://www.khronos.org/opengles/documentation/opengles1_0/html/glTexEnv.html"]Read this.[/url]

Share this post


Link to post
Share on other sites
[quote name='bluntman' timestamp='1305822484' post='4813057']
[url="http://www.khronos.org/opengles/documentation/opengles1_0/html/glTexEnv.html"]Read this.[/url]
[/quote]

Thanks for the fast reply ... but it didn't help me ... because it's very limited information and I am not understanding everything.

Share this post


Link to post
Share on other sites
[quote name='hesselKRaymond' timestamp='1305823277' post='4813059']
[quote name='bluntman' timestamp='1305822484' post='4813057']
[url="http://www.khronos.org/opengles/documentation/opengles1_0/html/glTexEnv.html"]Read this.[/url]
[/quote]

Thanks for the fast reply ... but it didn't help me ... because it's very limited information and I am not understanding everything.
[/quote]

It has the info you need though:
[quote]
If pname is GL_TEXTURE_ENV_COLOR, params is a pointer to an array that holds an RGBA color consisting of four values. The values are clamped to the range [0, 1] when they are specified. [i]C[/i][sub][i]c[/i][/sub] takes these four values.
The initial value of GL_TEXTURE_ENV_MODE is GL_MODULATE. The initial value of GL_TEXTURE_ENV_COLOR is (0, 0, 0, 0).
[/quote]


[color=#1C2837][size=2][color=#000088]float[/color][color=#000000] mycolor[/color][color=#666600][[/color][color=#006666]4[/color][color=#666600]];[/color][color=#000000]
mycolor[/color][color=#666600][[/color][color=#006666]0[/color][color=#666600]]=[/color][color=#000000]mycolor[/color][color=#666600][[/color][color=#006666]1[/color][color=#666600]]=[/color][color=#000000]mycolor[/color][color=#666600][[/color][color=#006666]2[/color][color=#666600]]=[/color][color=#006666]0.0[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]//RGB doesn't matter since it's not used[/color][color=#000000]
mycolor[/color][color=#666600][[/color][color=#006666]3[/color][color=#666600]]=[/color][color=#000000]blend[/color][color=#666600];[/color][color=#000000] [/color][color=#880000]//Set the blend factor with this[/color][color=#000000]
glTexEnvfv[/color][color=#666600]([/color][color=#000000]GL_TEXTURE_ENV[/color][color=#666600],[/color][color=#000000] GL_TEXTURE_ENV_COLOR[/color][color=#666600],[/color][color=#000000] mycolor[/color][color=#666600]);[/color][/size][/color]

From what I can tell [font=CourierNew, monospace][size=2]glColor4f does not effect the texture at all, only the colour given to glTexEnvfv does. So RGB does matter![/size][/font]
[font=CourierNew, monospace][size=2]Looks like it also needs to be used in conjunction with [/size][/font]GL_BLEND.

Share this post


Link to post
Share on other sites
If you want to multiply with a color you need GL_MODULATE on texture image unit 0
[code]
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glColor4f(x, y, z, w);
[/code]

Share this post


Link to post
Share on other sites
[quote name='V-man' timestamp='1305837857' post='4813187']
If you want to multiply with a color you need GL_MODULATE on texture image unit 0
[code]
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glColor4f(x, y, z, w);
[/code]

[/quote]

Thanks a lot ... I will try out your tips as soon as possible.

Share this post


Link to post
Share on other sites
Using the code above I have only been able to tint the first of the two textures and then blending them together. I haven't been able yet to tint the result of the combination of both textures. D:

Share this post


Link to post
Share on other sites
In that case, you would need another texture image unit. YOU MUST BIND A TEXTURE to the unit and enable the unit.

[code]
glActiveTexture(GL_TEXTURE2);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, someTexture);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_CONSTANT);
glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR );

float [/font]multColor[4];
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, multColor);
[/code]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By _OskaR
      Hi,
      I have an OpenGL application but without possibility to wite own shaders.
      I need to perform small VS modification - is possible to do it in an alternative way? Do we have apps or driver modifictions which will catch the shader sent to GPU and override it?
    • By xhcao
      Does sync be needed to read texture content after access texture image in compute shader?
      My simple code is as below,
      glUseProgram(program.get());
      glBindImageTexture(0, texture[0], 0, GL_FALSE, 3, GL_READ_ONLY, GL_R32UI);
      glBindImageTexture(1, texture[1], 0, GL_FALSE, 4, GL_WRITE_ONLY, GL_R32UI);
      glDispatchCompute(1, 1, 1);
      // Does sync be needed here?
      glUseProgram(0);
      glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer);
      glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                                     GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, texture[1], 0);
      glReadPixels(0, 0, kWidth, kHeight, GL_RED_INTEGER, GL_UNSIGNED_INT, outputValues);
       
      Compute shader is very simple, imageLoad content from texture[0], and imageStore content to texture[1]. Does need to sync after dispatchCompute?
    • By Jonathan2006
      My question: is it possible to transform multiple angular velocities so that they can be reinserted as one? My research is below:
      // This works quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); quat quaternion2 = GEMultiplyQuaternions(quaternion1, GEQuaternionFromAngleRadians(angleRadiansVector2)); quat quaternion3 = GEMultiplyQuaternions(quaternion2, GEQuaternionFromAngleRadians(angleRadiansVector3)); glMultMatrixf(GEMat4FromQuaternion(quaternion3).array); // The first two work fine but not the third. Why? quat quaternion1 = GEQuaternionFromAngleRadians(angleRadiansVector1); vec3 vector1 = GETransformQuaternionAndVector(quaternion1, angularVelocity1); quat quaternion2 = GEQuaternionFromAngleRadians(angleRadiansVector2); vec3 vector2 = GETransformQuaternionAndVector(quaternion2, angularVelocity2); // This doesn't work //quat quaternion3 = GEQuaternionFromAngleRadians(angleRadiansVector3); //vec3 vector3 = GETransformQuaternionAndVector(quaternion3, angularVelocity3); vec3 angleVelocity = GEAddVectors(vector1, vector2); // Does not work: vec3 angleVelocity = GEAddVectors(vector1, GEAddVectors(vector2, vector3)); static vec3 angleRadiansVector; vec3 angularAcceleration = GESetVector(0.0, 0.0, 0.0); // Sending it through one angular velocity later in my motion engine angleVelocity = GEAddVectors(angleVelocity, GEMultiplyVectorAndScalar(angularAcceleration, timeStep)); angleRadiansVector = GEAddVectors(angleRadiansVector, GEMultiplyVectorAndScalar(angleVelocity, timeStep)); glMultMatrixf(GEMat4FromEulerAngle(angleRadiansVector).array); Also how do I combine multiple angularAcceleration variables? Is there an easier way to transform the angular values?
    • By dpadam450
      I have this code below in both my vertex and fragment shader, however when I request glGetUniformLocation("Lights[0].diffuse") or "Lights[0].attenuation", it returns -1. It will only give me a valid uniform location if I actually use the diffuse/attenuation variables in the VERTEX shader. Because I use position in the vertex shader, it always returns a valid uniform location. I've read that I can share uniforms across both vertex and fragment, but I'm confused what this is even compiling to if this is the case.
       
      #define NUM_LIGHTS 2
      struct Light
      {
          vec3 position;
          vec3 diffuse;
          float attenuation;
      };
      uniform Light Lights[NUM_LIGHTS];
       
       
    • By pr033r
      Hello,
      I have a Bachelor project on topic "Implenet 3D Boid's algorithm in OpenGL". All OpenGL issues works fine for me, all rendering etc. But when I started implement the boid's algorithm it was getting worse and worse. I read article (http://natureofcode.com/book/chapter-6-autonomous-agents/) inspirate from another code (here: https://github.com/jyanar/Boids/tree/master/src) but it still doesn't work like in tutorials and videos. For example the main problem: when I apply Cohesion (one of three main laws of boids) it makes some "cycling knot". Second, when some flock touch to another it scary change the coordination or respawn in origin (x: 0, y:0. z:0). Just some streng things. 
      I followed many tutorials, change a try everything but it isn't so smooth, without lags like in another videos. I really need your help. 
      My code (optimalizing branch): https://github.com/pr033r/BachelorProject/tree/Optimalizing
      Exe file (if you want to look) and models folder (for those who will download the sources):
      http://leteckaposta.cz/367190436
      Thanks for any help...

  • Popular Now