Python - Minimal Modern OpenGL Shader Example

32 views
Skip to first unread message

kloffy

unread,
May 10, 2017, 8:03:48 PM5/10/17
to omegalib
Hi,

I have a very basic question, as I am just getting started. I am trying to get a minimal modern OpenGL example working in Python. For example, just a simple fullscreen quad.

Suppose this is my vertex shader:

#version 400

in vec4 aPosition;
in vec4 aColor;

out vec4 vPosition;
out vec4 vColor;

uniform mat4 transform
;
uniform mat4 projection
;

void main()
{
    vPosition
= transform * aPosition;
    vColor
= aColor;
    gl_Position
= projection * vPosition;
}

And this is my fragment shader:

#version 400

in vec4 vPosition;
in vec4 vColor;

layout
(location = 0) out vec4 color;

void main()
{    
    color
= vColor;
}

How do I setup the respective array buffer and vertex array objects from my Python script? Currently looking like this:

from cyclops import *

scene
= getSceneManager()

plainProgram
= ProgramAsset()
plainProgram
.name = "plain"
plainProgram
.vertexShaderName = "data/shaders/plain.vert"
plainProgram
.fragmentShaderName = "data/shaders/plain.frag"
scene
.addProgram(plainProgram)

Any pointers on how to complete the script so that it renders a simple quad with the shader program?

Many thanks,
kloffy

kloffy

unread,
May 10, 2017, 10:12:35 PM5/10/17
to omegalib
From browsing the source of cyclops, I get the impression that it is not really possible, since it is based on OSG and only exposes limited functionality. I wonder if there is any other way to achieve this using omegalib from Python?

Cheers,
kloffy

Alessandro Febretti

unread,
May 11, 2017, 11:57:55 AM5/11/17
to omegalib
You can do this through cyclops/OSG using ModelGeometry: example - https://github.com/omega-hub/cyclops/blob/master/examples/python/customGeometry.py

If you want to skip OSG and do OpenGL you can only use C++ at this time, since the relevant omegalib classes (GpuBuffer, GpuProgram, ...) don't have a python API yet.

An example of a C++ OpenGL module using OpenGL 4 and exposing a python API: https://github.com/omega-hub/overlay
Reply all
Reply to author
Forward
0 new messages