Cathy L.

2013-09-17 14:45:11 UTC

Hello

For multitexturing, here is my vertex shader:

---------------------------------

#version 330

uniform mat4 ModelViewProjectionMatrix;

in vec3 VertexPosition;

in vec2 ColorTexCoord;

in vec2 AlphaTexCoord;

out vec2 oColorTexCoord;

out vec2 oAlphaTexCoord;

invariant gl_Position;

void main(void)

{

oColorTexCoord=ColorTexCoord;

oAlphaTexCoord=AlphaTexCoord;

gl_Position=ModelViewProjectionMatrix*vec4(VertexPosition,1.0);

}

---------------------------------

and here is the fragment shader:

---------------------------------

#version 330

in vec2 oColorTexCoord;

in vec2 oAlphaTexCoord;

out vec4 FColor;

uniform sampler2DArray ColTex;

uniform sampler2DArray AlpTex;

uniform int nlayers;

void main(void)

{

vec3 t3dc=vec3(oColorTexCoord,floor(0.5));

vec4 color=texture(ColTex,t3dc);

vec4 alpha;

int i;

for (i=1;i<nlayers;i++)

{

t3dc=vec3(oAlphaTexCoord,floor(i-1+0.5));

alpha=texture(AlpTex,t3dc);

if (alpha.r>0.09)

{

t3dc=vec3(oColorTexCoord,floor(i+0.5));

if (alpha.r>0.91) color=texture3D(ColTex,t3dc);

else color=color*(1-alpha.r)+texture(ColTex,t3dc)*alpha.r;

}

}

FColor=color;

}

---------------------------------

The compilation works but when I get the indices this way:

---------------------------------

*pshp=gl33_InitShader("heightmap.vsh","heightmap.fsh");

if (*pshp==(unsigned int)-1) return FALSE;

glUseProgram(*pshp);

hm_uicol=glGetUniformLocation(*pshp,"ColTex");

hm_uialp=glGetUniformLocation(*pshp,"AlpTex");

hm_uinlayers=glGetUniformLocation(*pshp,"nlayers");

hm_uimMVP=glGetUniformLocation(*pshp,"ModelViewProjectionMatrix");

hm_uivpos=glGetAttribLocation(*pshp,"VertexPosition");

hm_uivtcol=glGetAttribLocation(*pshp,"ColorTexCoord");

hm_uivtalp=glGetAttribLocation(*pshp,"AlphaTexCoord");

glUseProgram(0);

---------------------------------

hm_uicol and hm_uialp return -1 when all others give an index>=0.

Could somebody tell me where is the problem?

Thanks a lot

Cathy L.

For multitexturing, here is my vertex shader:

---------------------------------

#version 330

uniform mat4 ModelViewProjectionMatrix;

in vec3 VertexPosition;

in vec2 ColorTexCoord;

in vec2 AlphaTexCoord;

out vec2 oColorTexCoord;

out vec2 oAlphaTexCoord;

invariant gl_Position;

void main(void)

{

oColorTexCoord=ColorTexCoord;

oAlphaTexCoord=AlphaTexCoord;

gl_Position=ModelViewProjectionMatrix*vec4(VertexPosition,1.0);

}

---------------------------------

and here is the fragment shader:

---------------------------------

#version 330

in vec2 oColorTexCoord;

in vec2 oAlphaTexCoord;

out vec4 FColor;

uniform sampler2DArray ColTex;

uniform sampler2DArray AlpTex;

uniform int nlayers;

void main(void)

{

vec3 t3dc=vec3(oColorTexCoord,floor(0.5));

vec4 color=texture(ColTex,t3dc);

vec4 alpha;

int i;

for (i=1;i<nlayers;i++)

{

t3dc=vec3(oAlphaTexCoord,floor(i-1+0.5));

alpha=texture(AlpTex,t3dc);

if (alpha.r>0.09)

{

t3dc=vec3(oColorTexCoord,floor(i+0.5));

if (alpha.r>0.91) color=texture3D(ColTex,t3dc);

else color=color*(1-alpha.r)+texture(ColTex,t3dc)*alpha.r;

}

}

FColor=color;

}

---------------------------------

The compilation works but when I get the indices this way:

---------------------------------

*pshp=gl33_InitShader("heightmap.vsh","heightmap.fsh");

if (*pshp==(unsigned int)-1) return FALSE;

glUseProgram(*pshp);

hm_uicol=glGetUniformLocation(*pshp,"ColTex");

hm_uialp=glGetUniformLocation(*pshp,"AlpTex");

hm_uinlayers=glGetUniformLocation(*pshp,"nlayers");

hm_uimMVP=glGetUniformLocation(*pshp,"ModelViewProjectionMatrix");

hm_uivpos=glGetAttribLocation(*pshp,"VertexPosition");

hm_uivtcol=glGetAttribLocation(*pshp,"ColorTexCoord");

hm_uivtalp=glGetAttribLocation(*pshp,"AlphaTexCoord");

glUseProgram(0);

---------------------------------

hm_uicol and hm_uialp return -1 when all others give an index>=0.

Could somebody tell me where is the problem?

Thanks a lot

Cathy L.