Home > Software engineering >  Opengl texture mapping is distorted tilted, why
Opengl texture mapping is distorted tilted, why

Time:09-20



Recently learn opengl, texture map, drawing up always tilted, why?
On the left is the original image, the effect of right is painted
The code below
//the Load and create a texture 
GLuint texture;
GlGenTextures (1, & amp; Texture);
GlActiveTexture (GL_TEXTURE0);
GlPixelStorei (GL_UNPACK_ALIGNMENT, 1);
GlBindTexture (GL_TEXTURE_2D, texture);//All upcoming GL_TEXTURE_2D operations now have effect on this texture object
//glUniform1i (glGetUniformLocation (shaderProgram, "ourTexture"), 0).//set the texture unit to 0
//Set the texture wrapping parameters
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);//Set texture wrapping to GL_REPEAT (usually basic wrapping method)
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Set texture filtering parameters
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MIN_FILTER, GL_LINEAR);
GlTexParameteri (GL_TEXTURE_2D GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//Load the image, create texture and generate mipmaps
Int width, height;
Unsigned char * image=SOIL_load_image (" container. JPG ", & amp; Width, & amp; Height, 0, SOIL_LOAD_RGBA);

Slog (" -- -- -- -- -- -- -- -- -- -- width=[% d] - height=[% d] ", width, height);
GlTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image).

GlGenerateMipmap (GL_TEXTURE_2D);
SOIL_free_image_data (image);
GlBindTexture (GL_TEXTURE_2D, 0);//Unbind texture when done, so we won 't accidentily mess up our texture.

GlBindTexture (GL_TEXTURE_2D, texture);

//glViewport (200, 200, 400, 400);

GlBindVertexArray (VAO);
GlDrawArrays (GL_TRIANGLES, 0, 3 * 2);

CodePudding user response:

I understand why, texture coordinates,
Vertex coordinates of the six, two triangles, the corresponding texture coordinates have to preach six, is also two triangles, so you don't have a problem

CodePudding user response:

Yes, TexCoord corresponding Vertex
  • Related