bgl: Vertex Arrays + GLSL shader (openGL shaded sphere)

Hi, I share this .blends: https://drive.google.com/file/d/0B3GouQIyoCmrNFNnVGljd0RfTEE/view?usp=sharing
to see different ways to draw a triangle with bgl and shade it with a GLSL shader.

Thanks for the help of HG1.

  1. Immediate mode
  2. Using glGenList, glNewList, glCallList
  3. With glDrawElements (Vertex Arrays) (the most modern way. Except vbo that aren’t supported in bgl)
  4. With glDrawArrays (Vertex Arrays)

This can of course be used to draw more complex polygons with better shaders

For noobs like me :slight_smile:

More infos here: http://www.songho.ca/opengl/gl_vertexarray.html

EDIT: A shaded sphere: https://drive.google.com/file/d/0B3GouQIyoCmrbTRGWDlKRmdGNzg/view?usp=sharing (with just a simplified diffuse) The original model of the sphere is hidden (alt+H to unhide). The sphere is in fact a subdivided cube to have only quads.

EDIT2: movingSphere: https://drive.google.com/file/d/0B3GouQIyoCmrV25wQ3gzaFRxb1U/view?usp=sharing :stuck_out_tongue:

Except vbo that aren’t supported in bgl

Since the last bgl update (I think it was Blender 2.75 or 2.76) VAO’s (glBindVertexArray) and VBO’s (glBindBuffer, glBufferData) are supported, but the new supported functions are not documented. So you have to try out which functions working now.
Or you can look into the actual list, which I grabbed from the source code.

The always true puls is not necessary if you use post_draw. Blender will call the added functions in the post_draw every frame.

To translate and rotate the mesh you can also use glTranslate and glRotatef, this will multiply the actual matrix with the translation resp. the rotations matrix.

Thanks very much HG1 for your tips and comments. I’ll try to do with vbo if it is possible and I’ll update the thread. Thanks :slight_smile: