   How does Shading with Textures work
  Hi,I am fairly new to OpenGL and completely new to OpenGL 3.2.The Tutorials I found on the web where all old and use TexCoord[0] and ftransform().I am experimenting with Textures and Shaders, but I can't get my texture to fit on my cube.All I get is a unicolored cube (I use the textures alpha map to switch between orange and white)My vertex shader:My fragment shader:uniform mat4 perspective;uniform mat4 view;uniform mat4 model;in vec4 vertex;in vec2 texCoordinates;in vec3 normal;out vec2 texCoord;void main() {texCoord = texCoordinates;gl_Position = perspective * view * model * vertex;}uniform sampler2D tex;in vec2 texCoord;out vec4 fragColor;void main() {vec4 color = texture2D(tex, texCoord);fragColor = mix(vec4(1.0, 0.5, 0.0, 1.0), vec4(1.0, 1.0, 1.0, 1.0), color.a);}I have tried to multiply texCoord with 0.1 or 1/512 to resize it (texture size is 512x512)   
Quote:All I get is a unicolored cubeWhat color is it?Quote:but I can't get my texture to fit on my cube.Are you sure it is properly UV mapped texture?Quote:I have tried to multiply texCoord with 0.1 or 1/512 to resize it (texture size is 512x512)Your texcoord should always be between 0 and 1 (or larger than 1 if you want repeating texture). Texture size is not relevant to the UV coords so you shouldn't have to scale them. 0,0 is at one corner of the texture, and 1,1 is at the other corner.Maybe post your supporting OpenGL code in addition to the shaders. There are a lot of points where you can make a mistake with texturing and I'd need to see more to help. Nothing in your shader stands out to me as incorrect.   ;  Thank you for your answer. I have just learned more about texturing.For loading the texture I use FreeImage, which has the following code in its demo TextureManager class (with some additions by myself)glActiveTexture(GL_TEXTURE0 + texID);glGenTextures(1, &gl_texID);glBindTexture(GL_TEXTURE_2D, gl_texID);glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height,0, GL_RGBA, GL_UNSIGNED_BYTE, bits);I also have additional Texture parameters setglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);The following is the actual rendering of the cube.The setUniform is just a wrapper, that fetches the Location and sets the value. Same is with enableVAA and disableVAA. The view and projection matrices are set globally and not changed with each cube.shader->setUniformM4fv("model", glm::gtx::type_ptr::value_ptr(this->modelMatrix));shader->setUniform1i("tex", 0);shader->enableVAA("texCoordinates", 2, glm::gtx::type_ptr::value_ptr(glm::vec2(0, 0)));shader->enableVAA("vertex", 4, vertices);glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, indices);shader->disableVAA("vertex");shader->disableVAA("texCoordinates");I hope I have provided all information you need, I tried to get all related to texturing in my code.   ;  Do you understand what I mean when I refer to UV mapping? Can you show the uv coordinates you are using for each vertex? (if you have them defined as a literal array).I'm just slightly confused by this pair of line:shader->enableVAA("texCoordinates", 2, glm::gtx::type_ptr::value_ptr(glm::vec2(0, 0)));shader->enableVAA("vertex", 4, vertices);I'm not sure totally what your wrapper function does, but how are you supplying the texture coordinate data to the array? I understand enableVAA(...,vertices), it looks like you are sending vertex data, but I don't get what that whole value_ptr to (0,0) is doing.If you still can't find it, you'll need to post your wrapper function definitions as well, as I can't tell what you're doing inside them. Also if that code corresponds to your drawing of the vertex arrays, please also show where you create them/load with data.Also very minor:glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);You probably want a WRAP_T in there instead of WRAP_S twice.;  This whole type_ptr::value_ptr thing is because OpenGL needs the Texture Coordinates (which I have set to 0,0) as a pointer afaik and not as a glm::vec2 object.enableVAA does the followingvoid Shader::enableVAA(const std::string key, const int size, void* ptr){   GLuint vaa = glGetAttributeLocation(this->program_handle, key.c_str());   glEnableVertexAttribArray(vaa);   glVertexAttribPointer(vaa, size, GL_FLOAT, GL_FALSE, 0, ptr);}and this is an example for a setUniform function (the other (setUniformM4fv) does the same with the according OpenGL function). program_handle is the handle for the shader program.void Shader::setUniform1i(const std::string key, int value) {   GLuint location = glGetUniformLocation(this->program_handle, key.c_str());   glUniform1i(location, value);}The vertices and indices are fixed arrays with hard coded data and work just fine with rendering the cube with a fixed color defined as a vec4 in the shader instead of the texture (this was my simple coloring method before I tried to add texturing).Did I do something wrong when passing the Texture Coordinates? How do I pass them without the wrappers, just plain OpenGL commands?   ;  So you're passing a pointer to ONE vec2 with the value (0, 0) as texture coordinates? You need as much texture coordinates as vertices you have, so, passing just one value won't work.   ;  I think you have a fundamental misunderstanding of what texture coordinates are.Say I have a quad that is drawn from -5,-5 to 5,5 (using immediate mode for simplicity)glVertex2f(-5,-5);glVertex2f(5,-5);glVertex2f(5,5);glVertex2f(-5,5);I have a texture loaded in memory that I would like to be drawn over this quad. I have to send a texture coordinate for each vertex.glTexCoord2f(0,0);glVertex2f(-5,-5);glTexCoord2f(1,0);glVertex2f(5,-5);glTexCoord2f(1,1);glVertex2f(5,5);glTexCoord2f(0,1);glVertex2f(-5,5);This means for the lower left vertex, use the bottom left corner of the texture. For the lower right vertex, use the bottom right corner of the texture, etc. Then the pixels in the quad are interpolated between these coordinates. When you set all texcoords to 0,0 you are telling the entire cube to interpolate from 0,0 to 0,0, which is just a single color pixel.This code will show that quad with the texture on top of it.If I change all of the 1's in my texcoords to 0.5, then it will draw the quad with only the bottom left quarter of the texture stretched over it.You should read some simple texturing tutorials to understand what you need to do.;  Hi,Thank you for your help. I misunderstood texture coordinates first, but as you told me they are between 0,0 and 1,1 it was a bit clearer.I looked at the tuorials from nopper.tv and found out, that I didn't see him using VBOs. He binds the VBO and passes 0 to with VertexAttribPointer and I thought this were the texture coordinates.   