When I run my program the texture on the cube seems to be orientated incorrectly & repeating itself. Also the white in the image has seemed to be replaced by green. I have tried removing the glColor tag but that just throws an error. It would be nice if someone also knew how to make it just show the raw image but it is not the end of the world if no one can.
It looks like this
The texture is meant to be this
This is my code:
import pygame
import sys
from OpenGL.GL import *
from OpenGL.GLU import *
from pygame.locals import *
verticies = (
(1, 1, 1), #0
(1, 1, -1), #1
(1, -1, 1), #2
(1, -1, -1), #3
(-1, 1, 1), #4
(-1, 1, -1), #5
(-1, -1, 1), #6
(-1, -1, -1), #7
)
# (<node1>, <node2>)
edges = (
(0, 1), #0
(0, 2), #1
(0, 4), #2
(1, 3), #3
(1, 5), #4
(2, 3), #5
(2, 6), #6
(3, 7), #7
(4, 5), #8
(4, 6), #9
(5, 7), #10
(6, 7), #11
)
# (<node1>, <node2>, <node3>, <node4>)
faces = (
(0, 1, 3, 2), #0
(0, 1, 5, 4), #1
(0, 2, 6, 4), #2
(1, 3, 7, 5), #3
(2, 3, 7, 6), #4
(4, 5, 7, 6), #5
)
def cube():
glBegin(GL_QUADS)
for face in faces:
for vertex in face:
glColor3fv((0, 1, 0))
glTexCoord2fv(edges[vertex])
glVertex3fv(verticies[vertex])
glEnd()
glBegin(GL_LINES)
for edge in edges:
for vertex in edge:
glColor3fv((0, 0, 0))
glVertex3fv(verticies[vertex])
glEnd()
def loadTexture():
textureSurface = pygame.image.load('test_image.png')
textureData = pygame.image.tostring(textureSurface, "RGBA", 1)
width = textureSurface.get_width()
height = textureSurface.get_height()
glEnable(GL_TEXTURE_2D)
texid = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, texid)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height,
0, GL_RGBA, GL_UNSIGNED_BYTE, textureData)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
def main():
pygame.init()
display = (800, 600)
pygame.display.set_mode(display, DOUBLEBUF|OPENGL)
## loadTexture()
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
glTranslatef(0.0, 0.0, -5)
glRotatef(0, 0, 0, 0)
shiftActive = 0
ctrlActive = 0
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
glTranslatef(0.03, 0, 0)
if event.key == pygame.K_RIGHT:
glTranslatef(-0.03, 0, 0)
if event.key == pygame.K_UP:
glTranslatef(0, -0.03, 0)
if event.key == pygame.K_DOWN:
glTranslatef(0, 0.03, 0)
if event.key == pygame.K_LSHIFT:
shiftActive = 1
if event.key == pygame.K_LCTRL:
ctrlActive = 1
if event.type == pygame.KEYUP:
if event.key == pygame.K_LSHIFT:
shiftActive = 0
if event.key == pygame.K_LCTRL:
ctrlActive = 0
# scroll controls !CURRENTLY IN CLIK MODE BECAUSE OF MOUSE ISSUES!
if shiftActive:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
glTranslatef(-0.03, 0, 0)
if event.button == 3:
glTranslatef(0.03, 0, 0)
elif ctrlActive:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
glTranslatef(0, 0, 0.03)
if event.button == 3:
glTranslatef(0, 0, -0.03)
else:
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
glTranslatef(0, -0.03, 0)
if event.button == 3:
glTranslatef(0, 0.03, 0)
## glRotatef(1, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
cube()
loadTexture()
pygame.display.flip()
pygame.time.wait(10)
main()
Anyone know what i'm doing wrong?
Again stack overflow does not like my code to description ratio so I have to add on random sentences to the end of my question to let me post it. I wish this was removed or just made an optional warning. I don't think going into depth to discuss the angle the image is out by & the percentage size the image should be compared to its current size for each face & giving the exact hex value of green that is overlaying the white in the texture will help anyone answer this question. FFS stack overflow.