
最近學opengl,紋理貼圖,圖畫上去總是傾斜的,為什么?
左邊是原圖,右邊是畫出來的效果
代碼如下
// Load and create a texture
GLuint texture;
glGenTextures(1, &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); // 設定紋理單元為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 image, create texture and generate mipmaps
int width, height;
unsigned char* image = SOIL_load_image("container.jpg", &width, &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);
uj5u.com熱心網友回復:
我明白原因了,紋理坐標傳得不對,頂點坐標傳了6個,畫了倆三角形,對應的紋理坐標也得傳6個,同樣是倆三角形,這樣才不會有問題
uj5u.com熱心網友回復:
對,TexCoord對應的是Vertex轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/55939.html
標籤:圖形處理/算法
上一篇:關于請教條狀物,如細絲狀的條形物體目標,之前我用OpenCV進行影像識別。
下一篇:顯示出創建套接字失敗,求教大佬?
