a hyper-minimalist (1 file) framework to bring the Processing design paradigm to a simple low-dependency C environment (Mac, Linux, Windows-Cygwin)
- 2D and 3D graphics, drawing primitives
- user input (mouse, keyboard)
- textures, shaders
- easy built-in perspective frustums
- clone this repostory
- in terminal type
makethenmake runor try the examples
- navigate to the /examples folder
cd examples- type
makethenmake run1ormake run2...
Install a package manager, like homebrew
brew update
brew install glew
best with Raspbian version Stretch (2017) or later
sudo raspi-config
under "Advanced options", set "GL Driver" to be "GL (Full KMS)"
if you don't have "GL Driver", you have an old version of Raspbian and you can ignore it.
install 2 dependencies
sudo apt-get update
sudo apt-get install libglew-dev libglfw3-devsetup(); // runs once at the beginning
update(); // runs every frame, first thing to run
// draw() is split out into 2 functions
draw3D(); // runs every frame, called first
draw2D(); // 2D in pixel coordinates, called after draw3Dcreate a .c file with the following:
#include "world.h"
void setup(){ }
void update(){ }
void draw3D(){ }
void draw2D(){ }
void keyDown(unsigned int key){ }
void keyUp(unsigned int key){ }
void mouseDown(unsigned int button){ }
void mouseUp(unsigned int button){ }
void mouseMoved(int x, int y){ }Compile your sketch with the following build command (MacOS), or use the makefile make. The following is an example for a file named world.c:
gcc -o world world.c -std=gnu99 -framework Carbon -framework OpenGL -framework GLUT
Done! To run: ./world or make run
ELAPSEDtime in secondskeyboard[256]array of keyboard ASCII state: T/F if pressedmouseXmouseYmouse location in pixelsmouseDownXmouseDownYmouse drag between click and releaseWIDTHHEIGHTREAD ONLY window dimensionsYEARMONTHDAYHOURMINUTESECONDalways updated time, date
toggleFullscreen();
loadTexture(filename, width, height);text("text", x, y, z);
void drawPoint(x, y, z);
void drawLine(x1, y1, z1, x2, y2, z2);
void drawRect(x, y, z, width, height);
void drawCircle(x, y, z, radius);
void drawSphere(x, y, z, radius);
void drawTetrahedron();
void drawOctahedron();
void drawHexahedron(); drawCube();
void drawIcosahedron();
void drawDodecahedron();calling noFill() will render all upcoming shapes as wireframe, see-through, and textures will no longer show. It will stay that way until you call fill().
functions affected by fill and noFill:
- drawRect
- drawCircle
- drawSphere
- drawTetrahedron.. all of the solids
loadShader(vertex_path, fragment_path);
setShaderUniform1f(shader, uniform, value);
setShaderUniformVec2f(shader, uniform, array);
setShaderUniformVec3f(shader, uniform, array);
setShaderUniformVec4f(shader, uniform, array);It's easy to get your bearings. Camera orientation is measured using horizontal coordinate system used in astronomy: altitude and azimuth.
firstPersonPerspective(): 3D look at horizonpolarPerspective(): 3D look at originorthoPerspective(x, y, width, height): 2D x,y
ORIGIN[3](x, y, z) the center of the worldHORIZON[3](azimuth, altitude, zoom) point on celestial sphere
TO MAKE 3D EASY the framework comes with keyboard and mouse handling and coordinate space visualizations. You must opt-out if you don't want these features.
default is SIMPLE_SETTINGS
SETTINGS = ADVANCED_SETTINGS;SIMPLE_SETTINGSADVANCED_SETTINGS
Simple and Advanced turn all the flags on or off
Flip individual flags for a unique combination of built-in features
SET_MOUSE_LOOKclick mouse move looks aroundSET_KEYBOARD_MOVEarrow keys,WASDmove viewSET_KEYBOARD_FUNCTIONSsee belowSET_SHOW_GROUNDcheckerboard 2D surfaceSET_SHOW_GRIDrepeating 3D grid axes lines
Example, set new features:
SETTINGS = SET_MOUSE_LOOK | SET_KEYBOARD_FUNCTIONS | SET_SHOW_GRID;toggle features:
SETTINGS ^= SET_SHOW_GROUND;ESCclose applicationFtoggle fullscreen+-zoom,.change field of viewPswitch between perspectives- first person
- polar
- orthographic
Gshow/hide 2D ground (2D infinitely-repeating scenery)Xshow/hide 3D axes (3D infinitely-repeating scenery)
Whenever possible, this framework uses standard OpenGL built-in functions. Here is an abbreviated list of important calls you may want to know.
glClearColor(0.0, 0.5, 1.0, 1.0)set RGBA background colorglColor4f(1.0, 0.0, 0.0, 1.0)set RGBA draw color
glTranslatef(x, y, z)glRotatef(angle, 1, 0, 0)glScalef(10, 10, 10)glMultMatrixf(m)glPushMatrix()glPopMatrix()
first load a texture
GLint myTexture = loadTexture(filename, width, height);
apply it on geometry
glBindTexture(GL_TEXTURE_2D, myTexture);
// draw things
glBindTexture(GL_TEXTURE_2D, 0);default
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)glBlendEquation(GL_FUNC_ADD)
color as transparency
glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR)glBlendEquation(GL_FUNC_ADD)
glMaterialfv(GL_FRONT, GL_DIFFUSE, white)set draw colorglEnable(GL_LIGHTING),glEnable(GL_LIGHT0)enable lightglLightfv(GL_LIGHT0, GL_DIFFUSE, white)set light colorglLightfv(GL_LIGHT0, GL_POSITION, pos)set light position
These are just a few useful functions. A classic resource for more information is the OpenGL Programming Guide ("the OpenGL red book"), look into:
- lighting effects, shadows, fog
- matrix stack
- depth buffer
- state machine
MIT

