Jump to content
  • Advertisement
Sign in to follow this  
smr

OpenGL Textures only display when the screen is in 16bpp

This topic is 4642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having an issue. I can't seem to locate the source of the problem. I have a simple OpenGL program written in Python using PyOpenGL and PIL. For some reason, my textures appear as they should when my display is in 16bpp mode, but in 32 it appears as a solid green or solid red. I've posted the code. It doesn't appear here *exactly* as it is in the original so it'd be easier to read. Here's my screen initialization:
    	glutInit(())
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH)
        glutInitWindowSize(width, height)
        self.window = glutCreateWindow(caption)
        
        glutReshapeFunc(self.resize)
        glutDisplayFunc(self.renderTask)
        glutKeyboardFunc(self.keyPressed)
        glutIdleFunc(self.mainTask)

        glEnable(GL_TEXTURE_2D)
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0, self.logicalWidth, self.logicalHeight, 0, -1.0, 1.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

glut Resize callback
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(0, self.logicalWidth, self.logicalHeight, 0, -1.0, 1.0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

Loading the texture
        image = Image.open(filename)
        image = image.convert('RGBA')
        self.width, self.height = image.size
        self.id = glGenTextures(1)
        glBindTexture(GL_TEXTURE_2D, self.id)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
        glTexImage2D(GL_TEXTURE_2D, 0, 4, self.width, self.height,
                     0, GL_RGBA, GL_UNSIGNED_BYTE, image.tostring('raw', 'RGBA'))

Finally, rendering
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
        glEnable(GL_TEXTURE_2D)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
        glBindTexture(GL_TEXTURE_2D, self.id)
        glBegin(GL_QUADS)
        glTexCoord2f(0,0); glVertex2f(x, y)
        glTexCoord2f(1,0); glVertex2f(x + w, y)
        glTexCoord2f(1,1); glVertex2f(x + w, y + h)
        glTexCoord2f(0,1); glVertex2f(x, y + h)
        glEnd()
        glFlush()
        glutSwapBuffers()

Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
Try to use GL_RGBA8 for the internal format of glTexImage2D, instead of 4. That may (or may not) solve your problem...

Tom

Share this post


Link to post
Share on other sites
Quote:
Original post by smr
Nope. No luck with that.

I'm afraid that in that case, all I can give is a few debugging tips:

Are you sure about the output of the image.tostring(...) function? Is it 32bpp? And I would suggest to put a glColor4f(1,1,1,1) call before drawing the quad to make sure that the red and green you see are indeed coming from the textures. Also, try GL_REPLACE instead of GL_DECAL for the glTexEnv. That way, alpha is ignored, which is useful for debugging. Finally, I would suggest trying glGetError to locate failed function-calls (if any).

Tom

[Edited by - dimebolt on November 4, 2005 6:43:23 AM]

Share this post


Link to post
Share on other sites
On a hunch, I tried disabling hardware acceleration from the troubleshooting tab of my display properties. The texture displayed as it should. I tried this because in order to watch videos I must disable acceleration also. If I don't, then videos look pink and green. I think there's a problem with my display drivers.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!