OpenGL texture mapping stubbornly refuses to work

后端 未结 4 1928
梦毁少年i
梦毁少年i 2021-01-15 17:40

I\'m writing a 2D game using SDL and OpenGL in the D programming language. At the moment it simply tries to render a texture-mapped quad to the screen. Problem is, the whole

相关标签:
4条回答
  • 2021-01-15 17:58

    Don't you need a glOrtho(0., 800, 600, 0., 0., 1.); in the paintGL function?

    0 讨论(0)
  • 2021-01-15 18:13

    One common mistake is to create/use an incomplete texture, see here.

    Your code does not show any call to :

    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR/*or GL_NEAREST*/);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*or GL_NEAREST*/);
    

    and also does not show any mipmap creation.

    You problem may be related to your texture being incomplete.

    0 讨论(0)
  • 2021-01-15 18:18

    Try enabling GL_COLOR_MATERIAL? I haven't used the fixed-functionality pipeline in a while, but I think that might do it.

    0 讨论(0)
  • 2021-01-15 18:24

    Just a vague theory here: have you tried drawing the vertices counter-clockwise instead of clockwise?

    glTexCoord2i(0, 0); glVertex2i(0, 0);
    glTexCoord2i(0, 1); glVertex2i(0, 64);
    glTexCoord2i(1, 1); glVertex2i(64, 64);
    glTexCoord2i(1, 0); glVertex2i(64, 0);
    
    0 讨论(0)
提交回复
热议问题