我目前正在OpenGL3.3中开发一个简单的3D场景,但是在尝试对对象进行纹理处理时 - 所有这些场景的纹理都是黑色的.但是,如果我将上下文版本更改为3.1; 在模型上正确渲染纹理没有问题.
我不确定这是否表明我使用的是被弃用的功能/方法,但我很难看出问题出在哪里.
设置纹理
(load texture from file)
...
glGenTextures(1, &TexID); // Create The Texture ( CHANGE )
glBindTexture(GL_TEXTURE_2D, TexID);
glTexImage2D(GL_TEXTURE_2D, 0, texture_bpp / 8, texture_width, texture_height, 0, texture_type, GL_UNSIGNED_BYTE, texture_imageData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
...
Run Code Online (Sandbox Code Playgroud)
将纹理绑定到渲染
// mLocation is the layout location in the shader, from glGetUniformLocation
// mTextureUnit is the specified texture unit to load into. Currently using 0.
// mTextureID is the ID of the loaded texture, as generated above.
glActiveTexture( …
Run Code Online (Sandbox Code Playgroud)