Problem of how to draw a GL_TEXTURE_CUBE in pyglet

103 views
Skip to first unread message

Nicky Mac

unread,
Apr 24, 2020, 12:05:36 PM4/24/20
to pyglet-users
I'm working with Python3.6 and Pyglet, Interested in displaying a very large number of variously textured blocks in Minecraft style., I wondered if using  GL_TEXTURE_CUBE_MAP  would improve performance compared to rendering the 6 faces each time.  Using cubemap (from https://www.programcreek.com/python/example/97888/pyglet.gl)   I created my cubes and noted the returned  identifiers. 
Having studied the lists of CubeMap issues, I could not find any example of such a cube actually being drawn  Bewildered by the range of gl and pyglet graphics calls possible, I still have no idea how to draw a textured cube,   I was excited to find that GL_TEXTURE_CUBE could be specified  in pyglet.graphics (tho not documented) but I can't get the draw to work. Here is my relevant code and output:

        x, y, z = position
        vertex_data = cube_vertices(x, y, z, 0.5)   # create vertex list
        glEnable(GL_TEXTURE_CUBE_MAP)
        glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap) # cubemap is the textured-cube identifier
        count = len(vertex_data)
        pyglet.graphics.draw(count,GL_TEXTURE_CUBE_MAP, None,  ('v3f/static', vertex_data), ('t3f/static')) 
  
    ('v3f/static', vertex_data), ('t3f/static'))
  File "C:\Python\Python36\lib\site-packages\pyglet\graphics\__init__.py", line 193, in draw
    for format, array in data:
TypeError: 'NoneType' object is not iterable

Greg Ewing

unread,
Apr 26, 2020, 6:34:18 AM4/26/20
to pyglet...@googlegroups.com
On 25/04/20 4:05 am, Nicky Mac wrote:
> I wondered if using GL_TEXTURE_CUBE_MAP  would improve performance
> compared to rendering the 6 faces each time.

> Having studied the lists of CubeMap issues, I could not find any example
> of such a cube actually being drawn.

I think you may be mistaken about what a cube map is. It's not
a way of drawing cubes; it's a way of mapping points on something
you're drawing to texture coordinates.

One of the things it's useful for is drawing a far-away background
such as a sky. You store an image of the sky as a cube map texture,
and then draw a big cube around your scene. The cube map texture mode
makes it render as though the faces of the cube were infinitely
far away.

The only relevance it has to rendering minecraft blocks is if you
wanted to render reflections of the surroundings in the faces of
the block, or something like that. Then you could use a cube map
texture of the environment as part of the rendering process.

But you still have to render the six faces of the cube as usual.
There's no shortcut for that.

Some more information about cube maps:
https://en.wikipedia.org/wiki/Cube_mapping
https://learnopengl.com/Advanced-OpenGL/Cubemaps

--
Greg

Nicky Mac

unread,
Apr 27, 2020, 5:59:12 AM4/27/20
to pyglet-users
Dear Greg,
many thanks for your reply and the explanatory references.  I feel illuminated!
Now I understand why my call self.batch.add(count,GL_TEXTURE_CUBE_MAP, None,  ('v3f/static', vertex_data)
demands a vertex list of 24 elements rather than 6.
Reply all
Reply to author
Forward
0 new messages