Skip to content

Instantly share code, notes, and snippets.

@rdb
rdb / comparison
Created December 12, 2013 17:46
comparison between macro-composites and compiling the files individually
$ composite_files=`cat p3dtoolbase_composite1.cxx | cut -d '"' -f 2`
$ time g++ -c $composite_files -I../../../build/dtool/ -I/usr/include/python2.7
real 0m4.643s
user 0m4.151s
sys 0m0.477s
$ time g++ -c p3dtoolbase_composite1.cxx -I../../../build/dtool/ -I/usr/include/python2.7
real 0m0.848s
@rdb
rdb / js_linux.py
Last active April 8, 2024 10:12
Access joysticks/game controllers from Python in Linux via the joystick driver. See https://discourse.panda3d.org/t/game-controllers-on-linux-without-pygame/14128
# Released by rdb under the Unlicense (unlicense.org)
# Based on information from:
# https://www.kernel.org/doc/Documentation/input/joystick-api.txt
import os, struct, array
from fcntl import ioctl
# Iterate over the joystick devices.
print('Available devices:')
@rdb
rdb / js_winmm.py
Last active February 17, 2024 10:04
Access game controllers from Python on Windows via the WinMM API. See https://discourse.panda3d.org/t/game-controllers-on-windows-without-pygame/14129
# Released by rdb under the Unlicense (unlicense.org)
# Further reading about the WinMM Joystick API:
# http://msdn.microsoft.com/en-us/library/windows/desktop/dd757116(v=vs.85).aspx
from math import floor, ceil
import time
import ctypes
import _winreg as winreg
from ctypes.wintypes import WORD, UINT, DWORD
from ctypes.wintypes import WCHAR as TCHAR
@rdb
rdb / main.py
Last active August 29, 2015 14:02 — forked from anonymous/main.py
# Simple render to texture
node = loader.loadModel("panda")
depthtex = Texture('depth')
depthtex.set_clear(1.0)
colortex = Texture('color')
colortex.set_clear((0, 0, 0, 1))
normaltex = Texture('normal')
@rdb
rdb / UBOs.py
Last active August 29, 2015 14:03 — forked from tobspr/UBOs.py
class Light:
def __init__(self):
self.pos = ParamVector3f(0)
self.color = ParamVector3f(1,1,0)
self.mvp = ParamMatrix4f(0)
self.struct = StructParameter()
array = ArrayParameter()
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
:audio(debug): create_AudioManager()
audio_library_name="p3openal_audio"
:audio(debug): dl_name="libp3openal_audio.so"
:audio(debug): symbol of get_audio_manager_func_openal_audio = 000007FEECD026F0
:audio(debug): Create_OpenALAudioManager()
AL lib: (EE) MMDevApiOpenPlayback: Device init failed: 0x80004005
:audio(error): OpenALAudioManager: alcOpenDevice(NULL): ALC couldn't open device
@rdb
rdb / v4l_check.c
Created September 24, 2014 12:13
Small programs that lists supported V4L2 formats.
#include <linux/videodev2.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
struct v4l2_fmtdesc fmt;
int i;
const char *dev;
int fd;
@rdb
rdb / example.py
Created February 22, 2015 01:02
Example GLSL shader in Panda with simple texture mapping
from panda3d.core import Shader
vshader = """#version 140
// Vertex inputs
in vec4 p3d_Vertex;
in vec2 p3d_MultiTexCoord0;
// Uniform inputs
uniform mat4 p3d_ModelViewProjectionMatrix;
@rdb
rdb / cg2glsl.py
Last active September 28, 2022 11:28
Convert Cg shaders designed for Panda3D to GLSL shaders. Requires cgc.exe to be installed (part of the NVIDIA Cg Toolkit)
import subprocess
import sys
import os
glsl_extensions = {'v': '.vert', 'f': '.frag', 'g': '.geom'}
if len(sys.argv) != 2:
print("Usage: cg2glsl.py something.sha")
sys.exit(1)
// clang -O3 gl-preferred-format.c -o gl-preferred-format -lGL -lglut
#include <stdio.h>
#define GL_GLEXT_PROTOTYPES
#if defined(__GNUC__) && (defined(__APPLE_CPP__) || defined(__APPLE_CC__))
#include <GLUT/glut.h>
#else
#include <GL/glut.h>