crazyfuturamanoob
October 22nd, 2008, 08:30 PM
Look at the image, and you see, that the texture rendered with opengl looks odd. The colors aren't correct, and it looks blurry.
http://img205.imageshack.us/img205/3769/gltestyx8.png
What I have done wrong? Why the colors aren't correct? What's wrong?
I made this function for creating textures from files:
def texture_from_file(filename, size):
texture = GLuint()
# open the file
file = open(filename, 'r')
width = size[0]
height = size[1]
# read the data in it and close the file
data = file.read()
file.close()
glGenTextures(1, texture)
OpenGL.GL.glBindTexture(GL_TEXTURE_2D, texture)
# when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST )
# when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
# build our texture mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data)
# return texture for user
return texture
And I draw it with this:
glBindTexture(GL_TEXTURE_2D, tex)
glBegin(GL_QUADS)
glTexCoord2d(0, 0); glVertex2d(0, 0)
glTexCoord2d(1, 0); glVertex2d(40, 0)
glTexCoord2d(1, 1); glVertex2d(40, 40)
glTexCoord2d(0, 1); glVertex2d(0, 40)
glEnd()
That texture is a 40x40 bitmap:
http://img147.imageshack.us/img147/4330/texud2.png
So what is the problem? Would somebody OpenGL expert tell me what I did wrong?
http://img205.imageshack.us/img205/3769/gltestyx8.png
What I have done wrong? Why the colors aren't correct? What's wrong?
I made this function for creating textures from files:
def texture_from_file(filename, size):
texture = GLuint()
# open the file
file = open(filename, 'r')
width = size[0]
height = size[1]
# read the data in it and close the file
data = file.read()
file.close()
glGenTextures(1, texture)
OpenGL.GL.glBindTexture(GL_TEXTURE_2D, texture)
# when texture area is small, bilinear filter the closest mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST )
# when texture area is large, bilinear filter the first mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
# build our texture mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, data)
# return texture for user
return texture
And I draw it with this:
glBindTexture(GL_TEXTURE_2D, tex)
glBegin(GL_QUADS)
glTexCoord2d(0, 0); glVertex2d(0, 0)
glTexCoord2d(1, 0); glVertex2d(40, 0)
glTexCoord2d(1, 1); glVertex2d(40, 40)
glTexCoord2d(0, 1); glVertex2d(0, 40)
glEnd()
That texture is a 40x40 bitmap:
http://img147.imageshack.us/img147/4330/texud2.png
So what is the problem? Would somebody OpenGL expert tell me what I did wrong?