C++ OpenGL,对简单球体进行纹理处理

C++ OpenGL,对简单球体进行纹理处理,c++,opengl,graphics,textures,glsl,C++,Opengl,Graphics,Textures,Glsl,我试图用OpenGL可编程管道对球体进行纹理处理,但不知道这里出了什么问题 初始化: earth = createSphere(1, 64, 32); glEnable(GL_TEXTURE_2D); earthTex = createTexture("textures/earth.jpg"); createTexture: GLuint createTexture(const char* fileName) { GLuint texID; int width, height,

我试图用OpenGL可编程管道对球体进行纹理处理,但不知道这里出了什么问题

初始化:

earth = createSphere(1, 64, 32);
glEnable(GL_TEXTURE_2D);
earthTex = createTexture("textures/earth.jpg");
createTexture:

GLuint createTexture(const char* fileName)
{
    GLuint texID;
    int width, height, imgFormat, internalFormat;
    float* imgData = getImage(fileName, &height, &width, &imgFormat);
    switch (imgFormat)
    {
    case GL_RED: internalFormat = GL_R8; break;
    case GL_RG: internalFormat = GL_RG8; break;
    case GL_RGB: internalFormat = GL_RGB8; break;
    case GL_RGBA: internalFormat = GL_RGBA8; break;
    default: fprintf(stderr, "\n Cannot get ImgType \n"); break;
    }
    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, imgFormat, GL_FLOAT, (void*) imgData);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glBindTexture(GL_TEXTURE_2D, 0);
    return texID;
}
RenderLoop:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, earthTex);
glUniform1i(glGetUniformLocation(programID, "colorTex"), 0);
earth->draw();
glBindTexture(GL_TEXTURE_2D, 0);
在vertexShader中,我将texCoords传递给FragmentShader,在那里我只调用类似于
fs\u out\u color=texture(colorTex,fs\u In\u texCoords)的东西
其中colorTex是均匀的。
我一评论出来,一切都很好(除了顶点着色)。
有人有线索吗?
谢谢

编辑: 那是我的碎片。正如你所见,没什么特别的

#version 150 core

uniform sampler2D colorTex;
in vec3 fs_in_color;
in vec2 fs_in_texCoods;
out vec4 fs_out_color;

void main(void) {
    fs_out_color = texture(colorTex, fs_in_texCoords);
}

Edit2:如果我将fs_out_color更改为fs_in_color(当前为法线),则一切正常。否则,OpenGL会在调用抽屉元素后声明无效的\u操作。

您可以添加片段着色器吗?(和:考虑使用<代码> GLY-KHRY-DEXGE/< COD>扩展从GL获得有价值的调试输出)。您的代码> GeimTAGE(…)< /C>函数实际上返回浮点像素?这看起来非常浪费,即使你加载HDR图像格式,你最终还是要将其存储在一个8位定点纹理中。这似乎特别浪费,因为每次调用该函数时都会出现内存泄漏。谢谢你的提示,我会解决这个问题,但这不应该解决我的问题。