PDA

View Full Version : trying to get 1st program to run : glcolor problem



meemoeuk
12-23-2016, 11:29 AM
Hi, just trying to get my 1st python - openGL program working.

Loaded openGL module, got a openGL window up.
Now I'm trying to draw. I'm referencing some example code from the net, but like most example code, its legacy, so it a tough fight for a complete beginner to update it to openGl 4.5.


display= (300,200)
screen = pygame.display.set_mode(display)
gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)
OpenGL.glColor(1,1,0)
#glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
Cube()
pygame.display.flip()

the glcolor command is causing a compile time error. I have to update glcolor to the 4.5 equivalent.
But its a nightmare trying to search the net for it, all google returns are dozens of tutorial pages with enormous walls of text explaining obsolete legacy code.
For me Google is effectively broken for the task of searching for example code for languages with lots of legacy versions.

So help me out please!
Whats the 4.5 version of glcolor? Where's the link for the programmer reference to openGL 4.5 commands?

thx

meemoeuk
12-23-2016, 03:51 PM
I've found a command which I think is the 4.5 version of glcolor

GL_COLOR

found in the OpenGL.GL module

however
trying to use this command with
OpenGL.GL.GL_COLOR(1,1,0)
results in the error :
TypeError: 'IntConstant' object is not callable

while trying to call it with
OpenGL.GL_COLOR(1,1,0)
results in the error
AttributeError: 'module' object has no attribute 'GL_COLOR'

anyone know how to call GL_COLOR ?

GClements
12-23-2016, 08:30 PM
GL_COLOR is an enumeration constant, not a function.

The closest thing to glColor() in 4.5 core is glVertexAttrib().

Dark Photon
12-24-2016, 11:10 AM
Hi, just trying to get my 1st python - openGL program working.

Loaded openGL module, got a openGL window up.
Now I'm trying to draw. I'm referencing some example code from the net, but like most example code, its legacy, so it a tough fight for a complete beginner to update it to openGl 4.5.


...
OpenGL.glColor(1,1,0)
...

the glcolor command is causing a compile time error. ... Whats the 4.5 version of glcolor? Where's the link for the programmer reference to openGL 4.5 commands?

I suspect you may not be using your OpenGL wrapper library properly. Is it PyOpenGL (often provided by a python-opengl package)?

If so, try this:


> python
Python 2.7.6 (default, Nov 21 2013, 15:55:38) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from OpenGL.GL import *
>>> glColor
<function glColor at 0x1c6a6e0>


Notice that there's a glColor function provided.

To get a list of all of the GL functions your wrapper library provides, do this:


> python
Python 2.7.6 (default, Nov 21 2013, 15:55:38) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import OpenGL.GL
>>> dir(OpenGL.GL)
...


This'll spew a "very" long list of constants and functions provided by PyOpenGL.

To get documentation on a specific API, do this:


>>> print OpenGL.GL.glColor.__doc__
glColor*f* -- convenience function to dispatch on argument type

dispatches to glColor3f, glColor2f, glColor4f, glColor3f, glColor2f, glColor4f
depending on the arguments passed...


Re GClements' comment, if the GL context your OpenGL wrapper library is creating is a 4.5 Compatibility context, then it offers glColor*() APIs. If it's a 4.5 Core context, then it doesn't provide these APIs. A separate issue is what your OpenGL wrapper library is exposing that the underlying OpenGL driver implementation provides. The above should help you get to the bottom of whether you've got access to the glColor*() compatibility APIs via your Python wrapper library and underlying OpenGL implementation.