Jump to content

  • Log In with Google      Sign In   
  • Create Account


FXACE

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

#4880309 GLSL - merging two textures

Posted by FXACE 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 FXACE 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)

glUseProgramObjectARB(shaderProgram);

glUniform1iARB(glGetUniformLocationARB(shaderProgram,"firstGrassTexture"),0);

glUniform1iARB(glGetUniformLocationARB(shaderProgram,"secondGrassTexture"),1);

glUniform1iARB(glGetUniformLocationARB(shaderProgram,"maskTexture"),2);

glUseProgramObjectARB(0);


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:


glActiveTextureARB(GL_TEXTURE0_ARB);

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

glActiveTextureARB(GL_TEXTURE1_ARB);

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

glActiveTextureARB(GL_TEXTURE2_ARB);

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

glActiveTextureARB(GL_TEXTURE0_ARB);

glUseProgramObjectARB(shaderProgram);




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 FXACE 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 FXACE on 03 November 2011 - 03:18 PM


gl_FragColor = mix(FirstTextureColor, SecondTextureColor, coeff);


Where:

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 FXACE 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 FXACE on 18 March 2011 - 04:32 PM

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

PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB;

PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB;


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

glCreateProgramObjectARB=(PFNGLCREATEPROGRAMOBJECTARBPROC)glGetProcAddress("glCreateProgramObjectARB");

...

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

-me


#4771259 OpenGL Superbible 5th Edition compile error.

Posted by FXACE on 08 February 2011 - 02:58 AM

Is problem not solved if you use this line:

#include <windows.h>

before

#include <GL/glut.h>

?






PARTNERS