Converting GLSL modern OpenGL 3.2

早过忘川 提交于 2019-12-05 21:06:57

The update of your GLSL code to the latest standards looks fine, except for the problem with texture2D(). As was already pointed out, the texture sampling functions are now overloaded, and texture() needs to be used instead of texture2D().

The remaining problems are mostly with updating the code to use the Core Profile, which deprecates many legacy features. Looking at the posted code, this includes:

  • Using VAOs (Vertex Array Objects) is mandatory for setting up vertex state. Use functions like glGenVertexArrays() and glBindVertexArray() to set up a VAO, and make sure that you have it bound while using vertex state setup functions like glVertexAttribPointer() and glEnableVertexAttribArray().

  • The GL_ALPHA texture format is not supported anymore. For using a texture format with a single 8-bit component, use GL_R8 for the internal format, and GL_RED for the format:

    glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, g->bitmap.width, g->bitmap.rows, 0,
                 GL_RED, GL_UNSIGNED_BYTE, g->bitmap.buffer);
    

    This will also require a minor change in the shader code, since the sampling value for the 1-component texture is now in the red component:

    outColor = vec4(1,1,1, texture2D(tex, texcoord).r) * color;
    

Instead of using texture2D in your fragment shader, you should be using texture :

void main(void) {
  outColor = vec4(1, 1, 1, texture(tex, texcoord).a) * color;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!