1

I'm on Mac OSX, and am running on Mountain Lion. A year or so ago, I installed PyGame so I could program in Eclipse. I was pretty satified, although the lack of code completion threw me off a bit. I plowed through it, and have managed to put up with everything so far. Then, today, I decided to try some PyOpenGL. I installed it using pip, and I copied and pasted he following code into my windows (I'm going to continue here as the actual code isnt the problem). Almost everything gives a warning. Almost everything. The sidebar is a solid wall of yellow.

Lines of code like

glBegin(GL_TRIANGLES)

give me errors like

undefined variable: GL_TRIANGLES
undefined variable: glBegin

Even going into Eclipse>Preferences>Pydev>Editor>Code Analysis and telling Eclipse to ignore undefined variables doesnt help. Other modules like Pygame do this for me too.

This bothers me. A lot. And I really don't want to be forced back into LWJGL and java.

Is there any way I can fix this problem once and for all?

#!/usr/bin/env python

from OpenGL.GL import *
from OpenGL.GLU import *

import pygame

def pyramid():

   glBegin(GL_TRIANGLES)

   glColor3f(1.0, 0.0, 0.0)      #   // Red
   glVertex3f(0.0, 1.0, 0.0)      #   // Top Of Triangle (Front)
   glColor3f(0.0, 1.0, 0.0)      #   // Green
   glVertex3f(-1.0, -1.0, 1.0)      #      // Left Of Triangle (Front)
   glColor3f(0.0, 0.0, 1.0)      #   // Blue
   glVertex3f(1.0, -1.0, 1.0)      #   // Right Of Triangle (Front)

   glColor3f(1.0, 0.0, 0.0)      #   // Red
   glVertex3f(0.0, 1.0, 0.0)      #   // Top Of Triangle (Right)
   glColor3f(0.0,0.0, 1.0)         #   // Blue
   glVertex3f(1.0, -1.0, 1.0)      #   // Left Of Triangle (Right)
   glColor3f(0.0, 1.0, 0.0)      #   // Green
   glVertex3f(1.0, -1.0, -1.0)      #      // Right Of Triangle (Right)

   glColor3f(1.0, 0.0, 0.0)      #   // Red
   glVertex3f(0.0, 1.0, 0.0)      #   // Top Of Triangle (Back)
   glColor3f(0.0,1.0, 0.0)         #   // Green
   glVertex3f(1.0, -1.0, -1.0)      #   // Left Of Triangle (Back)
   glColor3f(0.0, 0.0, 1.0)      #   // Blue
   glVertex3f(-1.0, -1.0, -1.0)   #      // Right Of Triangle (Back)

   glColor3f(1.0, 0.0, 0.0)      #   // Red
   glVertex3f(0.0, 1.0, 0.0)      #   // Top Of Triangle (Left)
   glColor3f(0.0, 0.0, 1.0)      #   // Blue
   glVertex3f(-1.0, -1.0, -1.0)   #      // Left Of Triangle (Left)
   glColor3f(0.0, 1.0, 0.0)      #   // Green
   glVertex3f(-1.0, -1.0, 1.0)      #      // Right Of Triangle (Left)

   glEnd()

   glBegin(GL_QUADS)

   glColor3f(0.0, 0.0, 1.0)
   glVertex3f(-1.0, -1.0, -1.0)
   glColor3f(0.0, 1.0, 0.0)
   glVertex3f(1.0, -1.0, -1.0)
   glColor3f(0.0, 0.0, 1.0)
   glVertex3f(1.0, -1.0, 1.0)
   glColor3f(0.0, 1.0, 0.0)
   glVertex3f(-1.0, -1.0, 1.0)

   glEnd()

def cube():
   glBegin(GL_QUADS)

   glColor3f(0.0, 1.0, 0.0)      #   // Set The Color To Green
   glVertex3f(1.0, 1.0, -1.0)      #   // Top Right Of The Quad (Top)
   glVertex3f(-1.0, 1.0, -1.0)      #   // Top Left Of The Quad (Top)
   glVertex3f(-1.0, 1.0, 1.0)      #   // Bottom Left Of The Quad (Top)
   glVertex3f(1.0, 1.0, 1.0)      #   // Bottom Right Of The Quad (Top)

   glColor3f(1.0, 0.5, 0.0)      #   // Set The Color To Orange
   glVertex3f(1.0, -1.0, 1.0)      #   // Top Right Of The Quad (Bottom)
   glVertex3f(-1.0, -1.0, 1.0)      #      // Top Left Of The Quad (Bottom)
   glVertex3f(-1.0, -1.0, -1.0)   #      // Bottom Left Of The Quad (Bottom)
   glVertex3f(1.0, -1.0, -1.0)      #      // Bottom Right Of The Quad (Bottom)

   glColor3f(1.0, 0.0, 0.0)      #   // Set The Color To Red
   glVertex3f(1.0, 1.0, 1.0)      #   // Top Right Of The Quad (Front)
   glVertex3f(-1.0, 1.0, 1.0)      #   // Top Left Of The Quad (Front)
   glVertex3f(-1.0, -1.0, 1.0)      #      // Bottom Left Of The Quad (Front)
   glVertex3f(1.0, -1.0, 1.0)      #   // Bottom Right Of The Quad (Front)

   glColor3f(1.0, 1.0, 0.0)      #   // Set The Color To Red
   glVertex3f(1.0, -1.0, -1.0)      #   // Top Right Of The Quad (Back)
   glVertex3f(-1.0, -1.0, -1.0)   #   // Top Left Of The Quad (Back)
   glVertex3f(-1.0, 1.0, -1.0)      #      // Bottom Left Of The Quad (Back)
   glVertex3f(1.0, 1.0, -1.0)      #   // Bottom Right Of The Quad (Back)

   glColor3f(0.0, 0.0, 1.0)      #   // Set The Color To Blue
   glVertex3f(-1.0, 1.0, 1.0)      #   // Top Right Of The Quad (Left)
   glVertex3f(-1.0, 1.0, -1.0)      #   // Top Left Of The Quad (Left)
   glVertex3f(-1.0, -1.0, -1.0)   #      // Bottom Left Of The Quad (Left)
   glVertex3f(-1.0, -1.0, 1.0)      #   // Bottom Right Of The Quad (Left)

   glColor3f(1.0, 0.0, 1.0)      #   // Set The Color To Violet
   glVertex3f( 1.0, 1.0, -1.0)      #   // Top Right Of The Quad (Right)
   glVertex3f( 1.0, 1.0, 1.0)      #   // Top Left Of The Quad (Right)
   glVertex3f( 1.0, -1.0, 1.0)      #   // Bottom Left Of The Quad (Right)
   glVertex3f( 1.0, -1.0, -1.0)   #      // Bottom Right Of The Quad (Right)


   glEnd()


if __name__ == "__main__":

   from sys import exit

   print ("Initalizing...")

   resolution = (400, 300)

   pygame.init()
   screen = pygame.display.set_mode(resolution, pygame.OPENGL|pygame.DOUBLEBUF)

   print ("Doing GL stuff...")
   glViewport(0, 0, resolution[0], resolution[1])

   glMatrixMode(GL_PROJECTION)
   glLoadIdentity()
   gluPerspective(45.0, float(resolution[0]) / resolution[1], 0.1, 1000.0)

   glMatrixMode(GL_MODELVIEW)
   glLoadIdentity()

   print ("More GL stuff...")
   glEnable(GL_DEPTH_TEST)

   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

   glShadeModel(GL_SMOOTH)
   glClearColor(0.0, 0.0, 0.0, 0.0)

   print ("Minor details...")
   clock = pygame.time.Clock()

   rot_tri = 0
   rot_quad = 0

   import random

   print ("Mainloop...")
   while True:

      for event in pygame.event.get():

         if event.type == pygame.QUIT:
            pygame.quit()
            exit()

      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

      glLoadIdentity()
      glTranslatef(-1.5, 0.0, -6.0)
      glRotatef(rot_tri, 0.0, 1.0, 0.0)
      pyramid()

      glLoadIdentity()
      glTranslate(1.5, 0.0, -6.0)
      glRotatef(rot_quad, 1.0, 0.0, 0.0)
      cube()

      rot_tri += 2.0
      rot_quad -= 1.5

      pygame.display.set_caption("hello_opengl.py FPS: %i" % clock.get_fps())

      pygame.display.flip()
      clock.tick()
pipsqueaker117
  • 2,280
  • 9
  • 35
  • 47
  • I have nothing constructive to add here except to say that I feel your pain: http://stackoverflow.com/questions/14260714/fake-unresolved-import-error-in-pydev. This os one of the reasons that I eventually abandoned PyDev and just spent the $100 on PyCharm, which I highly recommend. (Full disclosure: I actually expensed it to my job.) – BenDundee Feb 20 '13 at 20:43
  • Hm, so PyCharm will take care of things like this? It... it actually works? – pipsqueaker117 Feb 20 '13 at 20:48
  • Yeah it works great. It even gives you code completion...wait for it...by analyzing doc strings. So you specify parameter names and types in the doc string, and it gives you autocomplete, almost as good as working with C# in Visual Studio (almost). It's pretty genius. – BenDundee Feb 20 '13 at 21:22
  • No idea what that means (I'm a freshman in high school, I just muck around with programming for fun). Could you explain? But anyway: ooohh... aaaahh – pipsqueaker117 Feb 21 '13 at 03:51
  • I love PyCharm, but the same thing happens to me there. Other than the irritating red line everything is working fine. – zmbq Jun 09 '13 at 11:41

1 Answers1

0

I have no trouble using PyDev with Eclipse and PyOpenGL. I installed OpenGL with pip install pyopengl, then went into Window > Preferences > PyDev > Interpreter - Python. Without changing anything hit Apply. When prompted, selected the appropriate interpreter to refresh. Once it completes, close out of Preferences, then File > Restart. Immediately this works:

from OpenGL.GL import GL_TRIANGLES
g.d.d.c
  • 46,865
  • 9
  • 101
  • 111