Jump to content
  • Advertisement
Sign in to follow this  
Krux

OpenGL no image when i use both textures

This topic is 2480 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

[solved]
Hi

I have a problem with mixing two textures in the shader. One texture is a heightmap that i also use to shade my heights, and the other texture is a skybox for reflection. As long as I only use one texture to define the color of my fragment, everything works fine, until I start mixing those colors in the fragment shader, then the model is not rendered anymore at all. A fun fact is, that it not the problem to use both textures at the same time, because I use the heightmap all the time to define the height of the vertex, but as soon as the fragment is dependent from both textures i dont see anything anymore.

Here is a part of my sourcecode, please let me know if there is anything missing, so that you can answer my question properly


loading of the heightmap (8 bpp)

val textureHeightMap = glGenTextures
glBindTexture(GL_TEXTURE_2D, textureHeightMap)
glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, width, height, 0, GL_INTENSITY,GL_UNSIGNED_BYTE, data)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)


loading of the cubemap (32 pbb)

val textureCubeMap = glGenTextures
glBindTexture(GL_TEXTURE_CUBE_MAP, textureCubeMap);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
//Define all 6 faces
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(0) );
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(1) );
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(2) );
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(3) );
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(4) );
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, allData(5) );


the drawing function of my mesh

//shader is an object that encapsulates a linked shader program.
shader.use
shader.setUniform(textureLoc, 0)
shader.setUniform(skyboxLoc, 1)

glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, textureHeightMap)
glActiveTexture(GL_TEXTURE1)
glBindTexture(GL_TEXTURE_CUBE_MAP, textureHeightMap)

glDrawArrays(GL_TRIANGLES,0,36)


this is my fragment shader, it is just phong lighting added with reflection to cube map.

uniform vec3 u_lightDirection;
uniform sampler2D u_texture;
uniform samplerCube u_skybox;
uniform float u_width;
uniform vec3 u_camPos;

in vec3 v_pos;
in vec3 v_Normal;
in vec3 v_Dir;
in vec3 v_color;

out vec4 fragColor;

void main(void) {
float diffuse = max(dot(-u_lightDirection,normalize(v_Normal)),0)*0.9;
float phong = pow(max(dot(-normalize(u_lightDirection), reflect( v_Dir, normalize(v_Normal))), 0), 23);
float ambient = 0.5f;

vec2 texCoord = v_pos.xy/u_width;

float r = 0.5;

//vec4 col = r*texture(u_texture,texCoord);
vec4 col = r*vec4(v_color,1);
vec4 refl = (1-r)*texture(u_skybox,reflect(u_camPos-v_pos, v_Normal));


fragColor = vec4(diffuse+ambient)*col+refl+vec4(phong);

}



hope you don't mind that I did not post my entire sourcecode, just tho parts I think that are important. If you are courious about the sytax, it is Scala, a JVM language, so it is a wrapped opengl (lwjgl). Semicolons and braces for no-arg functions are not needed.

Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
Yay I solved it, sorry to bother you, in the end the error was not in the code that I've offered here. I did not implement the shader.setUniform method with an int only with a float. The compiler didn't tell me that it was autocasting and in the end that was the error.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!