简体   繁体   中英

OpenGl 2d Texture repeat (different results on different devices)

On my laptop (Intel HD Graphics) when I try to draw a texture it will wrap correctly. However when I use my desktop with a nvidia graphics card it won't wrap anymore and it will clamp to 0..1. My image loading coding is posted below. As you can see i explicitly set the texture wrap to repeat.

int x, y, comp;
GLuint texID;
unsigned char* data = stbi_load(filename, &x, &y, &comp, 0);
glGenTextures(1, &texID); 
glBindTexture(GL_TEXTURE_2D, texID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, x, y, 0, (comp == 3) ? GL_RGB : GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
stbi_image_free(data);
m_resourceMap[resID] = texID;

SOLVED It had to do with the way Intel HD Graphics and Nvidia implement GLSL. For some reason it Inte l implementation didn't like my shader program which transformed vertex coordinates to texture coordinates. however Intel didnt like this and wouldn't work unless i mapped the tex coords using gltexcoordpointer. so when I tested it out on nvidia, my old shader program which mapped texture coordinates worked fine and nvidia's implementation ignored my gltexcoordpointer mapping. I solved it by just making an attribute to pass in properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM