1
Context: I’m using pyopengl 3.0.2 and python 2.7 to make 3ds drawings in opengl, Ubuntu 14.04 as OS and intel hd 3000 as video board.
Problem: When executing any cube in opengl the cube becomes transparent, even without using alpha. I have already run on another computer the same code, with the same version of python and pyopengl, and the cube is not transparent.
I also tried with freeglut using C, and the cube remains transparent, it seems to be something from operating system or video card.
import OpenGL
from OpenGL.GLUT import *
from OpenGL.GL import *
from OpenGL.GLU import *
from sys import argv
def init():
glClearColor(1.0, 1.0, 1.0, 1.0)#cor de fundo
glEnable(GL_DEPTH_TEST)
glShadeModel(GL_FLAT)
ang = 0.0
def display():
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)#limpa a janela
# glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gluLookAt(2, 2, 5.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0)
glRotatef(ang, 1, 1, 0.4)
#cubo
glScalef(1.0, 1.0, 0.3)
glColor3f(0, 0, 1)#cor da figura
glutSolidCube(2.0)
glColor3f(1.0, 0.0, 0.0)#cor da figura
glutWireCube(2.0)
#torus
glColor3f(0, 1.0, 0.0)#cor da figura
glScalef(0.55, 1, 1.5)
glTranslatef(0, 0.9, 0)#muda a posicao da figura
glutSolidTorus(0.15, 1.4, 20, 85)
glutWireTorus(0.15, 1.4, 20, 85)
glFlush()#executa o desenho
def reashpe(w, h):
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0)
glMatrixMode(GL_MODELVIEW)
def keyboard(tecla, x, y):
global ang
if tecla == '1':
ang += 3
elif tecla == '2':
ang -= 3
glutPostRedisplay()
if __name__ == '__main__':
glutInit(argv)#inicializa o glut
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB)#especifica o uso de cores e buffers
glutInitWindowSize(500, 500)#especifica as dimensoes da janela
glutInitWindowPosition(100, 100)#especifica aonde a janela aparece na tela
glutCreateWindow("Desenhando uma linha")#cria a janela
init()
glutDisplayFunc(display)
glutReshapeFunc(reashpe)#funcao que sera redesenhada pelo GLUT
glutKeyboardFunc(keyboard)
glutMainLoop()
Try to convert to Webgl to see if the problem persists. Code like this, that runs here and does not run there is %@#% to solve.
– Miguel Angelo
And how do you convert to Webgl?
– 4ndr3