Able to see through cubes - opengl - pyopengl

Asked

Viewed 535 times

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.

  • And how do you convert to Webgl?

1 answer

1


The problem is simple by 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
  • It worked, but since the edges were the same color as the cube, you can’t see the cube clearly, because I’m not using light.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.