I’ve been trying all day to get a simple shaders example working. I’m now stuck on a version issue (version ‘130’ not supported), with the log and code below.
Whatever I change the version to, I get the same message, and when I leave the version out I get a message saying ‘in’ isn’t support (suggesting this is <1.3?). I’m using a Mac (MBP late '13, which apparently supports OpenGL 4.1) running Catalina.
Any help resolving this would be greatly appreciated!
Log
...
:loader: Model /usr/local/lib/python3.7/site-packages/panda3d/etc/../models/box.egg found in disk cache.
:shader: Preprocessing shader file: /Users/michael/mit/sli/scene/scene/glsl_simple.vert
:shader: Preprocessing shader file: /Users/michael/mit/sli/scene/scene/glsl_simple.frag
:display:gsg:glgsg(error): An error occurred while compiling GLSL vertex shader /Users/michael/mit/sli/scene/scene/glsl_simple.vert:
ERROR: /Users/michael/mit/sli/scene/scene/glsl_simple.vert:1: '' : version '130' is not supported
:display:gsg:glgsg(error): An error occurred while compiling GLSL fragment shader /Users/michael/mit/sli/scene/scene/glsl_simple.frag:
ERROR: /Users/michael/mit/sli/scene/scene/glsl_simple.frag:1: '' : version '130' is not supported
Vertex shader
#version 130
// Uniform inputs
uniform mat4 p3d_ModelViewProjectionMatrix;
// Vertex inputs
in vec4 p3d_Vertex;
void main() {
gl_Position = p3d_ModelViewProjectionMatrix * p3d_Vertex;
}
Fragment shader
#version 130
void main() {
gl_FragColor = vec4(0, 0, 0, 1);
}
Script
import os
import numpy as np
from direct.showbase.ShowBase import ShowBase
from panda3d.core import FrameBufferProperties, WindowProperties
from panda3d.core import GraphicsOutput, GraphicsPipe
from panda3d.core import Texture, PerspectiveLens, Shader
from panda3d.core import ConfigVariableString, ConfigVariableBool, Filename
import matplotlib.pyplot as plt
ConfigVariableString('background-color', '1.0 1.0 1.0 0.0') # sets background to white
class SceneSimulator(ShowBase):
def __init__(self):
"""Create an empty scene with no cameras."""
ShowBase.__init__(self)
# set up texture and graphics buffer
window_props = WindowProperties.size(1920, 1080)
frame_buffer_props = FrameBufferProperties()
buffer = self.graphicsEngine.make_output(self.pipe,
f'Buffer',
-2,
frame_buffer_props,
window_props,
GraphicsPipe.BFRefuseWindow, # don't open a window
self.win.getGsg(),
self.win
)
texture = Texture()
buffer.add_render_texture(texture, GraphicsOutput.RTMCopyRam)
self.buffer = buffer
# place a box in the scene
x, y, side_length = 0, 0, 1
box = self.loader.loadModel("models/box")
box.reparentTo(self.render)
box.setScale(side_length)
box.setPos(x - side_length / 2, y - side_length / 2, 0)
# set up camera
lens = PerspectiveLens()
lens.set_film_size(1920, 1080)
lens.set_fov(45, 30)
pos = (0, 6, 4)
camera = self.make_camera(buffer, lens=lens, camName=f'Camera')
camera.reparent_to(self.render)
camera.set_pos(*pos)
camera.look_at(box)
self.camera = camera
# load shaders
vert_path = '/Users/michael/mit/sli/scene/scene/glsl_simple.vert'
frag_path = '/Users/michael/mit/sli/scene/scene/glsl_simple.frag'
custom_shader = Shader.load(Shader.SL_GLSL, vertex=vert_path, fragment=frag_path)
box.set_shader(custom_shader)
def render_image(self) -> np.ndarray:
self.graphics_engine.render_frame()
texture = self.buffer.get_texture()
data = texture.get_ram_image()
frame = np.frombuffer(data, np.uint8)
frame.shape = (texture.getYSize(), texture.getXSize(), texture.getNumComponents())
frame = np.flipud(frame)
return frame
if __name__ == '__main__':
simulator = SceneSimulator()
image = simulator.render_image()
plt.imshow(image)
plt.show()