Able to see through cubes - opengl - pyopengl

1

Context: I'm using using pyopengl 3.0.2 and python 2.7 to do 3ds drawings in opengl, ubuntu 14.04 as OS and intel hd 3000 as video card.

Problem: When running any cube in opengl the cube becomes transparent even without using the alpha. I have already run the same code on another computer, with the same version of python and pyopengl, and the cube does not become transparent.

I also tried with freeglut using C, and the cube remains transparent, it seems to be something of an 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()
    
asked by anonymous 04.02.2015 / 01:42

1 answer

1

The problem is simple, analyzing the following snippet of your code:

glScalef(1.0, 1.0, 0.3)
glColor3f(0, 0, 1)#cor A
glutSolidCube(2.0)#renderiza cubo inteiro com cor A
glColor3f(1.0, 0.0, 0.0)#cor B
glutWireCube(2.0)#renderiza apenas bordas do cubo com cor B

We can conclude that you render with two different colors , so the final image will have two different colors.

Solution :

glScalef(1.0, 1.0, 0.3)
glColor3f(0, 0, 1)#cor A
glutSolidCube(2.0)#renderiza cubo inteiro com cor A  
glutWireCube(2.0)#renderiza apenas bordas do cubo com cor A
    
30.03.2015 / 06:06