Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Sep 2009
Offline Last Active Feb 18 2013 04:06 AM

#4880309 GLSL - merging two textures

Posted by on 03 November 2011 - 04:12 PM

Also I want to add:

gl_FragColor = mix(texture2D(firstGrassTexture,gl_TexCoord[0].xy), texture2D(secondGrassTexture,gl_TexCoord[0].xy), texture2D(maskTexture,gl_TexCoord[0].xy).a);

It would work if you loading "mask" texture as .png or any other format which supports 32-bit. Otherwise, you need to change value 'a' (alpha) of "texture2D(maskTexture,gl_TexCoord[0].xy).a" to one of the following channels:

x, r (red);

y, g (green);

z, b (blue);

which you set as mask channel.

Best wishes, FXACE.

#4880295 GLSL - merging two textures

Posted by on 03 November 2011 - 03:42 PM

No problem.

Which shader version you need? (1.0 is enough?)

Did you have the algorithm to load shaders?

//vertex shader

void main()


 gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

 gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;

// fragment/pixel shader

uniform sampler2D firstGrassTexture;

uniform sampler2D secondGrassTexture;

uniform sampler2D maskTexture;

void main()


 gl_FragColor = mix(texture2D(firstGrassTexture,gl_TexCoord[0].xy), texture2D(secondGrassTexture,gl_TexCoord[0].xy), texture2D(maskTexture,gl_TexCoord[0].xy).a); 

you need to do this in your application:

GLhadleARB shaderProgram; // somewhere defined in your application (of course it must be loaded)






The code which was introduced above is a initialization of uniforms setup (so, just call it once).

The next code you need to call each time when you render your object with this shader:


glBindTexture(...);// here you bind first grass texture


glBindTexture(...);// here you bind second grass texture


glBindTexture(...);// here you bind mask texture



Draw the mesh

glUseProgramObjectARB(0);// disable using shader (maybe you have some object below which you want to draw them without using shaders

Best wishes, FXACE.

#4880289 GLSL iPhone 2.0

Posted by on 03 November 2011 - 03:26 PM

use glBindAttibLocation with specified value which you want before calling glLinkProgram.

And then should be ok.

Best wishes, FXACE.

#4880284 GLSL - merging two textures

Posted by on 03 November 2011 - 03:18 PM

gl_FragColor = mix(FirstTextureColor, SecondTextureColor, coeff);


FirstTextureColor is a color returned by texture2D(<first texture>,...);

SecondTextureColor is a color returned by texture2D(<second texture>,...);

coeff -> X% of second texture and (100 - X)% of first texture.

Best wishes, FXACE.

#4877253 OpenGL TGA Textures

Posted by on 26 October 2011 - 10:26 AM

glEnable(GL_TEXTURE_2D) - checked.

glTexCoord (before each glVertex call) - nowhere. <<


glEnable(GL_DEPTH_TEST) - you enabled depth testing but you never cleaning it (depth buffer).


glOrtho(100,100,100,100,100,100) - bad usage of matrix setup (are you trying to render a single point?)

your primitive never would be projected into screen with this matrix.

As the results, you seeing white screen because you set clear color to white color (and nothing other would be drawn).

#4787730 Starting with Shaders

Posted by on 18 March 2011 - 04:32 PM

So, first of all, you need to to create function pointers of GL extensions:



Next stage is to receive pointers to these functions by glGetProcAddress, for example:



Note that glGetProcAddress works only after initialized GL context....

There are many references and tutorials out of there.... For example: http://www.codesampl...er_simple_vs2ps


#4771259 OpenGL Superbible 5th Edition compile error.

Posted by on 08 February 2011 - 02:58 AM

Is problem not solved if you use this line:

#include <windows.h>


#include <GL/glut.h>