I've been trying to do simple texture mapping with SOIL, and I've been having bizarre outputs..
The output ONLY displays when a PNG texture is loaded. (SOIL_load_OGL_texture) Other textures appear as a greyish or a white.
vertices passed as:
struct Vertex {
float position[3];
float texturepos[2];
};
Vertex vertices[] = { // w and h are width and height of square.
0,0,0,0,0,
w,0,0,1,0,
0,h,0,0,1,
w,0,0,1,0,
w,h,0,1,1,
0,h,0,0,1
};
vertex shader:
attribute vec2 texpos;
attribute vec3 position;
uniform mat4 transform;
varying vec2 pixel_texcoord;
void main(void) {
gl_Position=transform * vec4(position,1.0);
pixel_texcoord=texpos;
}
fragment shader:
varying vec2 pixel_texcoord;
uniform sampler2D texture;
void main(void) {
gl_FragColor=texture2D(texture,pixel_texcoord);
}
All of the uniforms and attributes are validated.
Texture trying to render:
(is 128x128, power of 2.)
Output [with normal shaders]:
However, I think the problem lies entirely in something really bizarre that happened when I tried to debug it.
I changed the fragment shader to:
varying vec2 pixel_texcoord;
uniform sampler2D texture;
void main(void) {
gl_FragColor=vec4(pixel_texcoord.x,0,pixel_texcoord.y,1);
}
And got this result: Something is very wrong with the texture coordinates, as according to the shader, Y is now X, and X no longer exists. Can anyone explain this?
If my texture coordinates are correctly positioned, then I'll start looking at another image library..
[EDIT] I tried loading an image through raw gimp-generated data, and it had the same problem. It's as if the texture coordinates are 1-dimensional..
#version
directives? – genpfault