Red Bear OS — microkernel OS in Rust, based on Redox
Derivative of Redox OS (https://www.redox-os.org) adding: - AMD GPU driver (amdgpu) via LinuxKPI compat layer - ext4 filesystem support (ext4d scheme daemon) - ACPI fixes for AMD bare metal (x2APIC, DMAR, IVRS, MCFG) - Custom branding (hostname, os-release, boot identity) Build system is full upstream Redox with RBOS overlay in local/. Patches for kernel, base, and relibc are symlinked from local/patches/ and protected from make clean/distclean. Custom recipes live in local/recipes/ with symlinks into the recipes/ search path. Build: make all CONFIG_NAME=redbear-full Sync: ./local/scripts/sync-upstream.sh
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <cairo/cairo.h>
|
||||
#include <orbital.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static void
|
||||
travel_path (cairo_t *cr)
|
||||
{
|
||||
|
||||
cairo_pattern_t *pat;
|
||||
|
||||
pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, 256.0);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_rectangle (cr, 0, 0, 256, 256);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
pat = cairo_pattern_create_radial (115.2, 102.4, 25.6,
|
||||
102.4, 102.4, 128.0);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
|
||||
cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
|
||||
cairo_set_source (cr, pat);
|
||||
cairo_arc (cr, 128.0, 128.0, 76.8, 0, 2 * M_PI);
|
||||
cairo_fill (cr);
|
||||
cairo_pattern_destroy (pat);
|
||||
|
||||
|
||||
double x = 305.6, /* parameters like cairo_rectangle */
|
||||
y = 25.6,
|
||||
width = 204.8,
|
||||
height = 204.8,
|
||||
aspect = 1.0, /* aspect ratio */
|
||||
corner_radius = height / 10.0; /* and corner curvature radius */
|
||||
|
||||
double radius = corner_radius / aspect;
|
||||
double degrees = M_PI / 180.0;
|
||||
|
||||
cairo_new_sub_path (cr);
|
||||
cairo_arc (cr, x + width - radius, y + radius, radius, -90 * degrees, 0 * degrees);
|
||||
cairo_arc (cr, x + width - radius, y + height - radius, radius, 0 * degrees, 90 * degrees);
|
||||
cairo_arc (cr, x + radius, y + height - radius, radius, 90 * degrees, 180 * degrees);
|
||||
cairo_arc (cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
|
||||
cairo_close_path (cr);
|
||||
|
||||
cairo_set_source_rgb (cr, 0.5, 0.5, 1);
|
||||
cairo_fill_preserve (cr);
|
||||
cairo_set_source_rgba (cr, 0.5, 0, 0, 0.5);
|
||||
cairo_set_line_width (cr, 10.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
|
||||
double xc = 128.0;
|
||||
double yc = 128.0;
|
||||
radius = 100.0;
|
||||
double angle1 = 45.0 * (M_PI/180.0); /* angles are specified */
|
||||
double angle2 = 180.0 * (M_PI/180.0); /* in radians */
|
||||
|
||||
cairo_set_line_width (cr, 10.0);
|
||||
cairo_arc (cr, xc, yc, radius, angle1, angle2);
|
||||
cairo_stroke (cr);
|
||||
|
||||
/* draw helping lines */
|
||||
cairo_set_source_rgba (cr, 1, 0.2, 0.2, 0.6);
|
||||
cairo_set_line_width (cr, 6.0);
|
||||
|
||||
cairo_arc (cr, xc, yc, 10.0, 0, 2*M_PI);
|
||||
cairo_fill (cr);
|
||||
|
||||
cairo_arc (cr, xc, yc, radius, angle1, angle1);
|
||||
cairo_line_to (cr, xc, yc);
|
||||
cairo_arc (cr, xc, yc, radius, angle2, angle2);
|
||||
cairo_line_to (cr, xc, yc);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
draw (cairo_surface_t *surface)
|
||||
{
|
||||
cairo_t *cr;
|
||||
cr = cairo_create (surface);
|
||||
travel_path (cr);
|
||||
cairo_destroy (cr);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
void * window = orb_window_new(-1, -1, width, height, "CairoDemo");
|
||||
|
||||
//Cairo
|
||||
uint32_t * frame_data = orb_window_data(window);
|
||||
cairo_surface_t *surface = cairo_image_surface_create_for_data((uint8_t*) frame_data, CAIRO_FORMAT_ARGB32, width, height, cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, width));
|
||||
cairo_create(surface);
|
||||
draw (surface);
|
||||
|
||||
orb_window_sync(window);
|
||||
|
||||
char running = 1;
|
||||
while (running) {
|
||||
void * event_iter = orb_window_events(window);
|
||||
|
||||
OrbEventOption event_option;
|
||||
do {
|
||||
event_option = orb_events_next(event_iter);
|
||||
switch (event_option.tag) {
|
||||
case OrbEventOption_Quit:
|
||||
running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (running && event_option.tag != OrbEventOption_None);
|
||||
|
||||
orb_events_destroy(event_iter);
|
||||
}
|
||||
orb_window_destroy(window);
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
# source is part of cookbook
|
||||
|
||||
[build]
|
||||
dependencies = [
|
||||
"cairo",
|
||||
"expat",
|
||||
"fontconfig",
|
||||
"freetype2",
|
||||
"liborbital",
|
||||
"libpng",
|
||||
"pixman",
|
||||
"zlib",
|
||||
]
|
||||
template = "custom"
|
||||
script = """
|
||||
"${CXX}" \
|
||||
$("${PKG_CONFIG}" --cflags cairo) \
|
||||
"${COOKBOOK_RECIPE}/cairo-demo.c" \
|
||||
-o cairo-demo \
|
||||
-static \
|
||||
$("${PKG_CONFIG}" --libs cairo) \
|
||||
-lorbital
|
||||
mkdir -pv "${COOKBOOK_STAGE}/bin"
|
||||
cp -v "cairo-demo" "${COOKBOOK_STAGE}/bin/cairo-demo"
|
||||
"""
|
||||
@@ -0,0 +1,30 @@
|
||||
[source]
|
||||
git = "https://github.com/abishekvashok/cmatrix"
|
||||
script = """
|
||||
autoreconf -i
|
||||
"""
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = [
|
||||
"ncursesw"
|
||||
]
|
||||
script = """
|
||||
export LIBS="-lncursesw"
|
||||
|
||||
COOKBOOK_CONFIGURE_FLAGS+=(
|
||||
--without-fonts
|
||||
)
|
||||
|
||||
"${COOKBOOK_CONFIGURE}" "${COOKBOOK_CONFIGURE_FLAGS[@]}"
|
||||
|
||||
sed -i -e 's|#define USE_TIOCSTI 1|/* #undef USE_TIOCSTI */|g' config.h
|
||||
|
||||
"${COOKBOOK_MAKE}" -j "${COOKBOOK_MAKE_JOBS}"
|
||||
"${COOKBOOK_MAKE}" install DESTDIR="${COOKBOOK_STAGE}"
|
||||
"""
|
||||
|
||||
[package]
|
||||
dependencies = [
|
||||
"terminfo"
|
||||
]
|
||||
@@ -0,0 +1,10 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/cpal.git"
|
||||
branch = "redox"
|
||||
upstream = "https://github.com/tomaka/cpal.git"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
script = """
|
||||
cookbook_cargo_examples beep
|
||||
"""
|
||||
@@ -0,0 +1,9 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/dynamic-example.git"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
cookbook_cargo
|
||||
"""
|
||||
@@ -0,0 +1,5 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/exampled.git"
|
||||
|
||||
[build]
|
||||
template = "cargo"
|
||||
@@ -0,0 +1,344 @@
|
||||
/* gears.c */
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
/* Conversion to GLUT by Mark J. Kilgard */
|
||||
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glu.h>
|
||||
#include <GL/osmesa.h>
|
||||
#include <orbital.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear
|
||||
teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void
|
||||
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth)
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++) {
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
}
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static void * buffer = NULL;
|
||||
static void * window = NULL;
|
||||
|
||||
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
|
||||
static GLuint limit;
|
||||
static GLuint count = 1;
|
||||
|
||||
static void
|
||||
sync(void)
|
||||
{
|
||||
glFinish();
|
||||
|
||||
uint32_t * frame_data = orb_window_data(window);
|
||||
uint32_t * image_data = (uint32_t *)buffer;
|
||||
|
||||
int i;
|
||||
for(i = 0; i < width * height; i++) {
|
||||
frame_data[i] = image_data[i] | 0xFF000000;
|
||||
}
|
||||
|
||||
orb_window_sync(window);
|
||||
}
|
||||
|
||||
static void
|
||||
draw(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
sync();
|
||||
|
||||
count++;
|
||||
if (count == limit) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
idle(void)
|
||||
{
|
||||
angle += 2.0;
|
||||
draw();
|
||||
}
|
||||
|
||||
/* new window size or exposure */
|
||||
static void
|
||||
reshape(int width, int height)
|
||||
{
|
||||
GLfloat h = (GLfloat) height / (GLfloat) width;
|
||||
|
||||
glViewport(0, 0, (GLint) width, (GLint) height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
static GLfloat pos[4] =
|
||||
{5.0, 5.0, 10.0, 0.0};
|
||||
static GLfloat red[4] =
|
||||
{0.8, 0.1, 0.0, 1.0};
|
||||
static GLfloat green[4] =
|
||||
{0.0, 0.8, 0.2, 1.0};
|
||||
static GLfloat blue[4] =
|
||||
{0.2, 0.2, 1.0, 1.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
if (argc > 1) {
|
||||
/* do 'n' frames then exit */
|
||||
limit = atoi(argv[1]) + 1;
|
||||
} else {
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
OSMesaContext ctx = OSMesaCreateContextExt(OSMESA_BGRA, 16, 0, 0, NULL);
|
||||
if (!ctx) {
|
||||
printf("OSMesaCreateContextExt failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
buffer = malloc(width * height * 4);
|
||||
if(!buffer) {
|
||||
printf("malloc failed\n");
|
||||
OSMesaDestroyContext(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!OSMesaMakeCurrent(ctx, buffer, GL_UNSIGNED_BYTE, width, height)) {
|
||||
printf("OSMesaMakeCurrent failed\n");
|
||||
OSMesaDestroyContext(ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
OSMesaPixelStore(OSMESA_Y_UP, 0);
|
||||
|
||||
OSMesaColorClamp(GL_TRUE);
|
||||
|
||||
window = orb_window_new_flags(-1, -1, width, height, "Gears", ORB_WINDOW_ASYNC);
|
||||
|
||||
init();
|
||||
|
||||
reshape(width, height);
|
||||
|
||||
char running = 1;
|
||||
while (running) {
|
||||
idle();
|
||||
|
||||
void * event_iter = orb_window_events(window);
|
||||
|
||||
OrbEventOption event_option;
|
||||
do {
|
||||
event_option = orb_events_next(event_iter);
|
||||
switch (event_option.tag) {
|
||||
case OrbEventOption_Quit:
|
||||
running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (running && event_option.tag != OrbEventOption_None);
|
||||
|
||||
orb_events_destroy(event_iter);
|
||||
}
|
||||
|
||||
orb_window_destroy(window);
|
||||
OSMesaDestroyContext(ctx);
|
||||
free(buffer);
|
||||
|
||||
return 0; /* ANSI C requires main to return int. */
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
[build]
|
||||
dependencies=[
|
||||
"liborbital",
|
||||
"mesa",
|
||||
"mesa-glu",
|
||||
"zlib",
|
||||
]
|
||||
template = "custom"
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
|
||||
${CXX} -O2 -I "${COOKBOOK_SYSROOT}/usr/include" \
|
||||
$LDFLAGS "${COOKBOOK_RECIPE}/gears.c" \
|
||||
-o gears -lorbital $("${PKG_CONFIG}" --libs glu) -lz
|
||||
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
|
||||
cp -v "gears" "${COOKBOOK_STAGE}/usr/bin/gears"
|
||||
"""
|
||||
@@ -0,0 +1,28 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/glutin.git"
|
||||
branch = "redox-0.30"
|
||||
upstream = "https://github.com/rust-windowing/glutin.git"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = [
|
||||
"mesa",
|
||||
"zlib"
|
||||
]
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
EXAMPLES=(
|
||||
window
|
||||
)
|
||||
for example in "${EXAMPLES[@]}"
|
||||
do
|
||||
cargo rustc \
|
||||
--target "$TARGET" \
|
||||
--release \
|
||||
--manifest-path "${COOKBOOK_SOURCE}/glutin_examples/Cargo.toml" \
|
||||
--example "${example}" \
|
||||
-- -C link-args="$LDFLAGS $("${TARGET}-pkg-config" --libs osmesa) -lz -lstdc++ -lc -lgcc"
|
||||
mkdir -pv "${COOKBOOK_STAGE}/bin"
|
||||
cp -v "target/${TARGET}/release/examples/${example}" "${COOKBOOK_STAGE}/bin/glutin_${example}"
|
||||
done
|
||||
"""
|
||||
@@ -0,0 +1,9 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/iced.git"
|
||||
branch = "redox"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
script = """
|
||||
cookbook_cargo_packages styling
|
||||
"""
|
||||
@@ -0,0 +1,8 @@
|
||||
[source]
|
||||
git = "https://gitlab.redox-os.org/redox-os/orbclient.git"
|
||||
|
||||
[build]
|
||||
template = "cargo"
|
||||
cargoexamples = [
|
||||
"simple"
|
||||
]
|
||||
@@ -0,0 +1,547 @@
|
||||
/*
|
||||
* Test OSMesa interface at 8, 16 and 32 bits/channel.
|
||||
*
|
||||
* Usage: osdemo [options]
|
||||
*
|
||||
* Options:
|
||||
* -f generate image files
|
||||
* -g render gradient and print color values
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <GL/osmesa.h>
|
||||
#include <GL/glu.h>
|
||||
#include <orbital.h>
|
||||
|
||||
#define WIDTH 600
|
||||
#define HEIGHT 600
|
||||
|
||||
static GLboolean DisplayImages = GL_FALSE;
|
||||
static GLboolean WriteFiles = GL_FALSE;
|
||||
static GLboolean Gradient = GL_FALSE;
|
||||
|
||||
|
||||
static void
|
||||
Sphere(float radius, int slices, int stacks)
|
||||
{
|
||||
GLUquadric *q = gluNewQuadric();
|
||||
gluQuadricNormals(q, GLU_SMOOTH);
|
||||
gluSphere(q, radius, slices, stacks);
|
||||
gluDeleteQuadric(q);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Cone(float base, float height, int slices, int stacks)
|
||||
{
|
||||
GLUquadric *q = gluNewQuadric();
|
||||
gluQuadricDrawStyle(q, GLU_FILL);
|
||||
gluQuadricNormals(q, GLU_SMOOTH);
|
||||
gluCylinder(q, base, 0.0, height, slices, stacks);
|
||||
gluDeleteQuadric(q);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
Torus(float innerRadius, float outerRadius, int sides, int rings)
|
||||
{
|
||||
/* from GLUT... */
|
||||
int i, j;
|
||||
GLfloat theta, phi, theta1;
|
||||
GLfloat cosTheta, sinTheta;
|
||||
GLfloat cosTheta1, sinTheta1;
|
||||
const GLfloat ringDelta = 2.0 * M_PI / rings;
|
||||
const GLfloat sideDelta = 2.0 * M_PI / sides;
|
||||
|
||||
theta = 0.0;
|
||||
cosTheta = 1.0;
|
||||
sinTheta = 0.0;
|
||||
for (i = rings - 1; i >= 0; i--) {
|
||||
theta1 = theta + ringDelta;
|
||||
cosTheta1 = cos(theta1);
|
||||
sinTheta1 = sin(theta1);
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
phi = 0.0;
|
||||
for (j = sides; j >= 0; j--) {
|
||||
GLfloat cosPhi, sinPhi, dist;
|
||||
|
||||
phi += sideDelta;
|
||||
cosPhi = cos(phi);
|
||||
sinPhi = sin(phi);
|
||||
dist = outerRadius + innerRadius * cosPhi;
|
||||
|
||||
glNormal3f(cosTheta1 * cosPhi, -sinTheta1 * cosPhi, sinPhi);
|
||||
glVertex3f(cosTheta1 * dist, -sinTheta1 * dist, innerRadius * sinPhi);
|
||||
glNormal3f(cosTheta * cosPhi, -sinTheta * cosPhi, sinPhi);
|
||||
glVertex3f(cosTheta * dist, -sinTheta * dist, innerRadius * sinPhi);
|
||||
}
|
||||
glEnd();
|
||||
theta = theta1;
|
||||
cosTheta = cosTheta1;
|
||||
sinTheta = sinTheta1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void Cube(float size)
|
||||
{
|
||||
size = 0.5 * size;
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
/* +X face */
|
||||
glNormal3f(1, 0, 0);
|
||||
glVertex3f(size, -size, size);
|
||||
glVertex3f(size, -size, -size);
|
||||
glVertex3f(size, size, -size);
|
||||
glVertex3f(size, size, size);
|
||||
|
||||
/* -X face */
|
||||
glNormal3f(-1, 0, 0);
|
||||
glVertex3f(-size, size, size);
|
||||
glVertex3f(-size, size, -size);
|
||||
glVertex3f(-size, -size, -size);
|
||||
glVertex3f(-size, -size, size);
|
||||
|
||||
/* +Y face */
|
||||
glNormal3f(0, 1, 0);
|
||||
glVertex3f(-size, size, size);
|
||||
glVertex3f( size, size, size);
|
||||
glVertex3f( size, size, -size);
|
||||
glVertex3f(-size, size, -size);
|
||||
|
||||
/* -Y face */
|
||||
glNormal3f(0, -1, 0);
|
||||
glVertex3f(-size, -size, -size);
|
||||
glVertex3f( size, -size, -size);
|
||||
glVertex3f( size, -size, size);
|
||||
glVertex3f(-size, -size, size);
|
||||
|
||||
/* +Z face */
|
||||
glNormal3f(0, 0, 1);
|
||||
glVertex3f(-size, -size, size);
|
||||
glVertex3f( size, -size, size);
|
||||
glVertex3f( size, size, size);
|
||||
glVertex3f(-size, size, size);
|
||||
|
||||
/* -Z face */
|
||||
glNormal3f(0, 0, -1);
|
||||
glVertex3f(-size, size, -size);
|
||||
glVertex3f( size, size, -size);
|
||||
glVertex3f( size, -size, -size);
|
||||
glVertex3f(-size, -size, -size);
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Draw red/green gradient across bottom of image.
|
||||
* Read pixels to check deltas.
|
||||
*/
|
||||
static void
|
||||
render_gradient(void)
|
||||
{
|
||||
GLfloat row[WIDTH][4];
|
||||
int i;
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glOrtho(-1, 1, -1, 1, -1, 1);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex2f(-1, -1.0);
|
||||
glVertex2f(-1, -0.9);
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex2f(1, -0.9);
|
||||
glVertex2f(1, -1.0);
|
||||
glEnd();
|
||||
glFinish();
|
||||
|
||||
glReadPixels(0, 0, WIDTH, 1, GL_RGBA, GL_FLOAT, row);
|
||||
for (i = 0; i < 4; i++) {
|
||||
printf("row[i] = %f, %f, %f\n", row[i][0], row[i][1], row[i][2]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
render_image(void)
|
||||
{
|
||||
static const GLfloat light_ambient[4] = { 0.0, 0.0, 0.0, 1.0 };
|
||||
static const GLfloat light_diffuse[4] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
static const GLfloat light_specular[4] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
static const GLfloat light_position[4] = { 1.0, 1.0, 1.0, 0.0 };
|
||||
static const GLfloat red_mat[4] = { 1.0, 0.2, 0.2, 1.0 };
|
||||
static const GLfloat green_mat[4] = { 0.2, 1.0, 0.2, 1.0 };
|
||||
static const GLfloat blue_mat[4] = { 0.2, 0.2, 1.0, 1.0 };
|
||||
#if 0
|
||||
static const GLfloat yellow_mat[4] = { 0.8, 0.8, 0.0, 1.0 };
|
||||
#endif
|
||||
static const GLfloat purple_mat[4] = { 0.8, 0.4, 0.8, 0.6 };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 50.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glTranslatef(0, 0.5, -7);
|
||||
|
||||
glClearColor(0.3, 0.3, 0.7, 0.0);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(20.0, 1.0, 0.0, 0.0);
|
||||
|
||||
/* ground */
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBegin(GL_POLYGON);
|
||||
glNormal3f(0, 1, 0);
|
||||
glTexCoord2f(0, 0); glVertex3f(-5, -1, -5);
|
||||
glTexCoord2f(1, 0); glVertex3f( 5, -1, -5);
|
||||
glTexCoord2f(1, 1); glVertex3f( 5, -1, 5);
|
||||
glTexCoord2f(0, 1); glVertex3f(-5, -1, 5);
|
||||
glEnd();
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-1.5, 0.5, 0.0);
|
||||
glRotatef(90.0, 1.0, 0.0, 0.0);
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red_mat );
|
||||
Torus(0.275, 0.85, 20, 20);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-1.5, -0.5, 0.0);
|
||||
glRotatef(270.0, 1.0, 0.0, 0.0);
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green_mat );
|
||||
Cone(1.0, 2.0, 16, 1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(0.95, 0.0, -0.8);
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue_mat );
|
||||
glLineWidth(2.0);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
Sphere(1.2, 20, 20);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
glPopMatrix();
|
||||
|
||||
#if 0
|
||||
glPushMatrix();
|
||||
glTranslatef(0.75, 0.0, 1.3);
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, yellow_mat );
|
||||
glutWireTeapot(1.0);
|
||||
glPopMatrix();
|
||||
#endif
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-0.25, 0.0, 2.5);
|
||||
glRotatef(40, 0, 1, 0);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, purple_mat );
|
||||
Cube(1.0);
|
||||
glDisable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_LIGHTING);
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
init_context(void)
|
||||
{
|
||||
const GLint texWidth = 64, texHeight = 64;
|
||||
GLubyte *texImage;
|
||||
int i, j;
|
||||
|
||||
/* checker image */
|
||||
texImage = (GLubyte *)malloc(texWidth * texHeight * 4);
|
||||
for (i = 0; i < texHeight; i++) {
|
||||
for (j = 0; j < texWidth; j++) {
|
||||
int k = (i * texWidth + j) * 4;
|
||||
if ((i % 5) == 0 || (j % 5) == 0) {
|
||||
texImage[k+0] = 200;
|
||||
texImage[k+1] = 200;
|
||||
texImage[k+2] = 200;
|
||||
texImage[k+3] = 255;
|
||||
}
|
||||
else {
|
||||
if ((i % 5) == 1 || (j % 5) == 1) {
|
||||
texImage[k+0] = 50;
|
||||
texImage[k+1] = 50;
|
||||
texImage[k+2] = 50;
|
||||
texImage[k+3] = 255;
|
||||
}
|
||||
else {
|
||||
texImage[k+0] = 100;
|
||||
texImage[k+1] = 100;
|
||||
texImage[k+2] = 100;
|
||||
texImage[k+3] = 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, texImage);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
|
||||
free(texImage);
|
||||
}
|
||||
|
||||
static void
|
||||
display_image(const char *filename, const GLubyte *buffer, int width, int height)
|
||||
{
|
||||
void * window = orb_window_new(-1, -1, width, height, filename);
|
||||
|
||||
uint32_t * frame_data = orb_window_data(window);
|
||||
uint32_t * image_data = (uint32_t *)buffer;
|
||||
|
||||
int x, y;
|
||||
for(y = 0; y < height; y++) {
|
||||
for(x = 0; x < width; x++) {
|
||||
frame_data[y * width + x] = image_data[(height - 1 - y) * width + x] | 0xFF000000;
|
||||
}
|
||||
}
|
||||
|
||||
orb_window_sync(window);
|
||||
|
||||
char running = 1;
|
||||
while (running) {
|
||||
void * event_iter = orb_window_events(window);
|
||||
|
||||
OrbEventOption event_option;
|
||||
do {
|
||||
event_option = orb_events_next(event_iter);
|
||||
switch (event_option.tag) {
|
||||
case OrbEventOption_Quit:
|
||||
running = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (running && event_option.tag != OrbEventOption_None);
|
||||
|
||||
orb_events_destroy(event_iter);
|
||||
}
|
||||
|
||||
orb_window_destroy(window);
|
||||
}
|
||||
|
||||
static void
|
||||
write_ppm(const char *filename, const GLubyte *buffer, int width, int height)
|
||||
{
|
||||
const int binary = 0;
|
||||
FILE *f = fopen( filename, "w" );
|
||||
if (f) {
|
||||
int i, x, y;
|
||||
const GLubyte *ptr = buffer;
|
||||
if (binary) {
|
||||
fprintf(f,"P6\n");
|
||||
fprintf(f,"# ppm-file created by osdemo.c\n");
|
||||
fprintf(f,"%i %i\n", width,height);
|
||||
fprintf(f,"255\n");
|
||||
fclose(f);
|
||||
f = fopen( filename, "ab" ); /* reopen in binary append mode */
|
||||
for (y=height-1; y>=0; y--) {
|
||||
for (x=0; x<width; x++) {
|
||||
i = (y*width + x) * 4;
|
||||
fputc(ptr[i], f); /* write red */
|
||||
fputc(ptr[i+1], f); /* write green */
|
||||
fputc(ptr[i+2], f); /* write blue */
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
/*ASCII*/
|
||||
int counter = 0;
|
||||
fprintf(f,"P3\n");
|
||||
fprintf(f,"# ascii ppm file created by osdemo.c\n");
|
||||
fprintf(f,"%i %i\n", width, height);
|
||||
fprintf(f,"255\n");
|
||||
for (y=height-1; y>=0; y--) {
|
||||
for (x=0; x<width; x++) {
|
||||
i = (y*width + x) * 4;
|
||||
fprintf(f, " %3d %3d %3d", ptr[i], ptr[i+1], ptr[i+2]);
|
||||
counter++;
|
||||
if (counter % 5 == 0)
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static GLboolean
|
||||
test(GLenum type, GLint bits, const char *filename)
|
||||
{
|
||||
const GLint z = 16, stencil = 0, accum = 0;
|
||||
OSMesaContext ctx;
|
||||
void *buffer;
|
||||
GLint cBits;
|
||||
|
||||
assert(bits == 8 ||
|
||||
bits == 16 ||
|
||||
bits == 32);
|
||||
|
||||
assert(type == GL_UNSIGNED_BYTE ||
|
||||
type == GL_UNSIGNED_SHORT ||
|
||||
type == GL_FLOAT);
|
||||
|
||||
ctx = OSMesaCreateContextExt(OSMESA_BGRA, z, stencil, accum, NULL );
|
||||
if (!ctx) {
|
||||
printf("OSMesaCreateContextExt() failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Allocate the image buffer */
|
||||
buffer = malloc(WIDTH * HEIGHT * 4 * bits / 8);
|
||||
if (!buffer) {
|
||||
printf("Alloc image buffer failed!\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Bind the buffer to the context and make it current */
|
||||
if (!OSMesaMakeCurrent( ctx, buffer, type, WIDTH, HEIGHT )) {
|
||||
printf("OSMesaMakeCurrent (%d bits/channel) failed!\n", bits);
|
||||
free(buffer);
|
||||
OSMesaDestroyContext(ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* sanity checks */
|
||||
glGetIntegerv(GL_RED_BITS, &cBits);
|
||||
if (cBits != bits) {
|
||||
fprintf(stderr, "Unable to create %d-bit/channel renderbuffer.\n", bits);
|
||||
fprintf(stderr, "May need to recompile Mesa with CHAN_BITS=16 or 32.\n");
|
||||
return 0;
|
||||
}
|
||||
glGetIntegerv(GL_GREEN_BITS, &cBits);
|
||||
assert(cBits == bits);
|
||||
glGetIntegerv(GL_BLUE_BITS, &cBits);
|
||||
assert(cBits == bits);
|
||||
glGetIntegerv(GL_ALPHA_BITS, &cBits);
|
||||
assert(cBits == bits);
|
||||
|
||||
if (WriteFiles)
|
||||
printf("Rendering %d bit/channel image: %s\n", bits, filename);
|
||||
else
|
||||
printf("Rendering %d bit/channel image\n", bits);
|
||||
|
||||
OSMesaColorClamp(GL_TRUE);
|
||||
|
||||
init_context();
|
||||
render_image();
|
||||
if (Gradient)
|
||||
render_gradient();
|
||||
|
||||
/* Make sure buffered commands are finished! */
|
||||
glFinish();
|
||||
|
||||
if (DisplayImages && filename != NULL) {
|
||||
if (type == GL_UNSIGNED_SHORT) {
|
||||
GLushort *buffer16 = (GLushort *) buffer;
|
||||
GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
|
||||
int i;
|
||||
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
|
||||
buffer8[i] = buffer16[i] >> 8;
|
||||
display_image(filename, buffer8, WIDTH, HEIGHT);
|
||||
free(buffer8);
|
||||
}
|
||||
else if (type == GL_FLOAT) {
|
||||
GLfloat *buffer32 = (GLfloat *) buffer;
|
||||
GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
|
||||
int i;
|
||||
/* colors may be outside [0,1] so we need to clamp */
|
||||
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
|
||||
buffer8[i] = (GLubyte) (buffer32[i] * 255.0);
|
||||
display_image(filename, buffer8, WIDTH, HEIGHT);
|
||||
free(buffer8);
|
||||
}
|
||||
else {
|
||||
display_image(filename, (const GLubyte *)buffer, WIDTH, HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
if (WriteFiles && filename != NULL) {
|
||||
if (type == GL_UNSIGNED_SHORT) {
|
||||
GLushort *buffer16 = (GLushort *) buffer;
|
||||
GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
|
||||
int i;
|
||||
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
|
||||
buffer8[i] = buffer16[i] >> 8;
|
||||
write_ppm(filename, buffer8, WIDTH, HEIGHT);
|
||||
free(buffer8);
|
||||
}
|
||||
else if (type == GL_FLOAT) {
|
||||
GLfloat *buffer32 = (GLfloat *) buffer;
|
||||
GLubyte *buffer8 = (GLubyte *) malloc(WIDTH * HEIGHT * 4);
|
||||
int i;
|
||||
/* colors may be outside [0,1] so we need to clamp */
|
||||
for (i = 0; i < WIDTH * HEIGHT * 4; i++)
|
||||
buffer8[i] = (GLubyte) (buffer32[i] * 255.0);
|
||||
write_ppm(filename, buffer8, WIDTH, HEIGHT);
|
||||
free(buffer8);
|
||||
}
|
||||
else {
|
||||
write_ppm(filename, (const GLubyte *)buffer, WIDTH, HEIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
OSMesaDestroyContext(ctx);
|
||||
|
||||
free(buffer);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main( int argc, char *argv[] )
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("Use -f to write image files\n");
|
||||
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strcmp(argv[i], "-d") == 0)
|
||||
DisplayImages = GL_TRUE;
|
||||
else if (strcmp(argv[i], "-f") == 0)
|
||||
WriteFiles = GL_TRUE;
|
||||
else if (strcmp(argv[i], "-g") == 0)
|
||||
Gradient = GL_TRUE;
|
||||
}
|
||||
|
||||
test(GL_UNSIGNED_BYTE, 8, "image8.ppm");
|
||||
test(GL_UNSIGNED_SHORT, 16, "image16.ppm");
|
||||
test(GL_FLOAT, 32, "image32.ppm");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = [
|
||||
"liborbital",
|
||||
"mesa",
|
||||
"mesa-glu",
|
||||
"zlib"
|
||||
]
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
|
||||
cp "${COOKBOOK_SOURCE}/../osdemo.c" ./osdemo.c
|
||||
${CXX} -O2 -I "${COOKBOOK_SYSROOT}/include" $LDFLAGS osdemo.c -o osdemo \
|
||||
-lorbital $("${PKG_CONFIG}" --libs glu) -lz
|
||||
mkdir -pv "${COOKBOOK_STAGE}/usr/bin"
|
||||
cp -v "osdemo" "${COOKBOOK_STAGE}/usr/bin/osdemo"
|
||||
"""
|
||||
@@ -0,0 +1,19 @@
|
||||
[source]
|
||||
git = "https://github.com/jackpot51/pixelcannon.git"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
script = """
|
||||
cookbook_cargo
|
||||
|
||||
mkdir -pv "${COOKBOOK_STAGE}/apps/pixelcannon"
|
||||
cp -Rv "${COOKBOOK_SOURCE}/assets" "${COOKBOOK_STAGE}/apps/pixelcannon"
|
||||
|
||||
mkdir -pv "${COOKBOOK_STAGE}/usr/share/ui/apps"
|
||||
cp -v "${COOKBOOK_SOURCE}/manifest" "${COOKBOOK_STAGE}/usr/share/ui/apps/pixelcannon"
|
||||
"""
|
||||
|
||||
[package]
|
||||
dependencies = [
|
||||
"orbital",
|
||||
]
|
||||
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 168 KiB |
Binary file not shown.
@@ -0,0 +1,523 @@
|
||||
/* gears.c */
|
||||
|
||||
/*
|
||||
* 3-D gear wheels. This program is in the public domain.
|
||||
*
|
||||
* Brian Paul
|
||||
*/
|
||||
|
||||
/* Conversion to GLUT by Mark J. Kilgard */
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
||||
Draw a gear wheel. You'll probably want to call this function when
|
||||
building a display list since we do a lot of trig here.
|
||||
|
||||
Input: inner_radius - radius of hole at center
|
||||
outer_radius - radius at center of teeth
|
||||
width - width of gear
|
||||
teeth - number of teeth
|
||||
tooth_depth - depth of tooth
|
||||
|
||||
**/
|
||||
|
||||
static void
|
||||
gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
|
||||
GLint teeth, GLfloat tooth_depth)
|
||||
{
|
||||
GLint i;
|
||||
GLfloat r0, r1, r2;
|
||||
GLfloat angle, da;
|
||||
GLfloat u, v, len;
|
||||
|
||||
r0 = inner_radius;
|
||||
r1 = outer_radius - tooth_depth / 2.0;
|
||||
r2 = outer_radius + tooth_depth / 2.0;
|
||||
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
|
||||
glShadeModel(GL_FLAT);
|
||||
|
||||
glNormal3f(0.0, 0.0, 1.0);
|
||||
|
||||
/* draw front face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw front sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glNormal3f(0.0, 0.0, -1.0);
|
||||
|
||||
/* draw back face */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw back sides of teeth */
|
||||
glBegin(GL_QUADS);
|
||||
da = 2.0 * M_PI / teeth / 4.0;
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
/* draw outward faces of teeth */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i < teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
|
||||
u = r2 * cos(angle + da) - r1 * cos(angle);
|
||||
v = r2 * sin(angle + da) - r1 * sin(angle);
|
||||
len = sqrt(u * u + v * v);
|
||||
u /= len;
|
||||
v /= len;
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), width * 0.5);
|
||||
glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da), -width * 0.5);
|
||||
u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
|
||||
v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
|
||||
glNormal3f(v, -u, 0.0);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5);
|
||||
glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5);
|
||||
glNormal3f(cos(angle), sin(angle), 0.0);
|
||||
}
|
||||
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
|
||||
glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
|
||||
|
||||
glEnd();
|
||||
|
||||
glShadeModel(GL_SMOOTH);
|
||||
|
||||
/* draw inside radius cylinder */
|
||||
glBegin(GL_QUAD_STRIP);
|
||||
for (i = 0; i <= teeth; i++)
|
||||
{
|
||||
angle = i * 2.0 * M_PI / teeth;
|
||||
|
||||
glNormal3f(-cos(angle), -sin(angle), 0.0);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
|
||||
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
static int width = 800;
|
||||
static int height = 600;
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_GLContext context = NULL;
|
||||
|
||||
static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
|
||||
static GLint gear1, gear2, gear3;
|
||||
static GLfloat angle = 0.0;
|
||||
static GLfloat delta = 2.0f;
|
||||
|
||||
static void
|
||||
draw(void)
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(view_rotx, 1.0, 0.0, 0.0);
|
||||
glRotatef(view_roty, 0.0, 1.0, 0.0);
|
||||
glRotatef(view_rotz, 0.0, 0.0, 1.0);
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.0, -2.0, 0.0);
|
||||
glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
glCallList(gear1);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(3.1, -2.0, 0.0);
|
||||
glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear2);
|
||||
glPopMatrix();
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(-3.1, 4.2, 0.0);
|
||||
glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
|
||||
glCallList(gear3);
|
||||
glPopMatrix();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
static void
|
||||
idle(void)
|
||||
{
|
||||
angle += delta;
|
||||
if (angle > 360.0f)
|
||||
angle -= 360.0f;
|
||||
|
||||
draw();
|
||||
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
|
||||
/* new window size or exposure */
|
||||
static void
|
||||
reshape(int width, int height)
|
||||
{
|
||||
GLfloat h = (GLfloat)height / (GLfloat)width;
|
||||
|
||||
glViewport(0, 0, (GLint)width, (GLint)height);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glTranslatef(0.0, 0.0, -40.0);
|
||||
}
|
||||
|
||||
static void
|
||||
init(void)
|
||||
{
|
||||
static GLfloat pos[4] =
|
||||
{5.0, 5.0, 10.0, 0.0};
|
||||
static GLfloat red[4] =
|
||||
{0.8, 0.1, 0.0, 1.0};
|
||||
static GLfloat green[4] =
|
||||
{0.0, 0.8, 0.2, 1.0};
|
||||
static GLfloat blue[4] =
|
||||
{0.2, 0.2, 1.0, 1.0};
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, pos);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
/* make the gears */
|
||||
gear1 = glGenLists(1);
|
||||
glNewList(gear1, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
|
||||
gear(1.0, 4.0, 1.0, 20, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear2 = glGenLists(1);
|
||||
glNewList(gear2, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
|
||||
gear(0.5, 2.0, 2.0, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
gear3 = glGenLists(1);
|
||||
glNewList(gear3, GL_COMPILE);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
|
||||
gear(1.3, 2.0, 0.5, 10, 0.7);
|
||||
glEndList();
|
||||
|
||||
glEnable(GL_NORMALIZE);
|
||||
}
|
||||
|
||||
void CheckSDLError(int line)
|
||||
{
|
||||
const char *error = SDL_GetError();
|
||||
if (error != "")
|
||||
{
|
||||
printf("SLD Error: %s\n", error);
|
||||
|
||||
if (line != -1)
|
||||
printf("\nLine: %d\n", line);
|
||||
|
||||
SDL_ClearError();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Surface *image;
|
||||
const char *IMAGE_FILE_NAME = "/usr/games/sdl2_gears/assets/image.png";
|
||||
|
||||
Mix_Music *music = NULL;
|
||||
const char *MUSIC_FILE_NAME = "/usr/games/sdl2_gears/assets/music.wav";
|
||||
|
||||
TTF_Font *font = NULL;
|
||||
const char *TTF_FILE_NAME = "/usr/games/sdl2_gears/assets/font.ttf";
|
||||
|
||||
void cleanup()
|
||||
{
|
||||
if (context != NULL)
|
||||
{
|
||||
SDL_GL_DeleteContext(context);
|
||||
context = NULL;
|
||||
}
|
||||
if (window != NULL)
|
||||
{
|
||||
SDL_DestroyWindow(window);
|
||||
window = NULL;
|
||||
}
|
||||
|
||||
if (image != NULL)
|
||||
{
|
||||
SDL_FreeSurface(image);
|
||||
image = NULL;
|
||||
IMG_Quit();
|
||||
}
|
||||
|
||||
if (music != NULL)
|
||||
{
|
||||
Mix_FreeMusic(music);
|
||||
music = NULL;
|
||||
Mix_CloseAudio();
|
||||
}
|
||||
|
||||
if (font != NULL)
|
||||
{
|
||||
TTF_CloseFont(font);
|
||||
font = NULL;
|
||||
}
|
||||
|
||||
// Shutdown SDL 2
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Main
|
||||
printf("Initializing SDL\n");
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
|
||||
{
|
||||
printf("Failed to init SDL\n");
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Video / window
|
||||
printf("Creating SDL window\n");
|
||||
window = SDL_CreateWindow(
|
||||
"Gears",
|
||||
-1,
|
||||
-1,
|
||||
width,
|
||||
height,
|
||||
SDL_WINDOW_OPENGL);
|
||||
if (window == NULL)
|
||||
{
|
||||
printf("Unable to create window\n");
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Creating SDL GL context\n");
|
||||
context = SDL_GL_CreateContext(window);
|
||||
if (context == NULL)
|
||||
{
|
||||
printf("Unable to create SDL GL context\n");
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
reshape(width, height);
|
||||
|
||||
// Image
|
||||
printf("Initializing SDL image supporting formats png and jpeg\n");
|
||||
int flags = IMG_INIT_JPG | IMG_INIT_PNG;
|
||||
int initted = IMG_Init(flags);
|
||||
if ((initted & flags) != flags)
|
||||
{
|
||||
printf("IMG_Init: Failed to init required jpg and png support: %s\n", IMG_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
image = IMG_Load(IMAGE_FILE_NAME);
|
||||
if (image == NULL)
|
||||
{
|
||||
printf("IMG_Load failed: %s\n", IMG_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Audio
|
||||
printf("Opening SDL mixer audio\n");
|
||||
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0)
|
||||
{
|
||||
fprintf(stderr, "Couldn't open audio mixer: %s\n", SDL_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
music = Mix_LoadMUS(MUSIC_FILE_NAME);
|
||||
if (music == NULL)
|
||||
{
|
||||
fprintf(stderr, "Couldn't open audio file %s: %s\n", MUSIC_FILE_NAME, SDL_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Mix_PlayMusic(music, -1) < 0)
|
||||
{
|
||||
fprintf(stderr, "Couldn't play music: %s\n", SDL_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TTF
|
||||
printf("Initializing TTF\n");
|
||||
if (TTF_Init() < 0)
|
||||
{
|
||||
printf("Failed to init TTF\n");
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
font = TTF_OpenFont(TTF_FILE_NAME, 30);
|
||||
if (font == NULL)
|
||||
{
|
||||
printf("Couldn't open TTF file %s: %s\n", TTF_FILE_NAME, SDL_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
|
||||
int running = 1;
|
||||
SDL_Event event;
|
||||
int playing_audio = 0;
|
||||
while (running)
|
||||
{
|
||||
idle();
|
||||
|
||||
// Loop track
|
||||
Mix_PlayingMusic();
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
if (event.type == SDL_QUIT)
|
||||
running = 0;
|
||||
|
||||
if (event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch (event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_p:
|
||||
{
|
||||
if (!Mix_PlayingMusic())
|
||||
{
|
||||
if (Mix_PlayMusic(music, -1) < 0)
|
||||
{
|
||||
fprintf(stderr, "Couldn't play music: %s\n", SDL_GetError());
|
||||
CheckSDLError(__LINE__);
|
||||
cleanup();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mix_PausedMusic())
|
||||
{
|
||||
Mix_ResumeMusic();
|
||||
}
|
||||
else
|
||||
{
|
||||
Mix_PauseMusic();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SDLK_a:
|
||||
case SDLK_LEFT:
|
||||
{
|
||||
delta -= 0.2f;
|
||||
break;
|
||||
}
|
||||
case SDLK_d:
|
||||
case SDLK_RIGHT:
|
||||
{
|
||||
delta += 0.2f;
|
||||
break;
|
||||
}
|
||||
case SDLK_ESCAPE:
|
||||
{
|
||||
running = 0;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
if (event.button.button == SDL_BUTTON_LEFT)
|
||||
{
|
||||
printf("Left mouse btn pressed at position %d,%d\n", event.button.x, event.button.y);
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_MIDDLE)
|
||||
{
|
||||
printf("Middle mouse btn pressed at position %d,%d\n", event.button.x, event.button.y);
|
||||
}
|
||||
else if (event.button.button == SDL_BUTTON_RIGHT)
|
||||
{
|
||||
printf("Right mouse btn pressed at position %d,%d\n", event.button.x, event.button.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(10);
|
||||
}
|
||||
|
||||
cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
[build]
|
||||
template = "custom"
|
||||
dependencies = [
|
||||
"sdl2-image",
|
||||
"sdl2-mixer",
|
||||
"sdl2-ttf",
|
||||
]
|
||||
script = """
|
||||
DYNAMIC_INIT
|
||||
mkdir -p "${COOKBOOK_STAGE}/usr/games/sdl2_gears"
|
||||
${CXX} -O2 -I "${COOKBOOK_SYSROOT}/include" $LDFLAGS ${COOKBOOK_RECIPE}/gears.c \
|
||||
-o sdl2_gears -dynamic \
|
||||
-lSDL2_image -lSDL2_mixer -lSDL2_ttf $("${PKG_CONFIG}" --libs osmesa) \
|
||||
-lSDL2 -lorbital -lfreetype -lpng -ljpeg -lvorbisfile -lvorbis -logg -lz
|
||||
cp -rv "${COOKBOOK_RECIPE}/assets" "${COOKBOOK_STAGE}/usr/games/sdl2_gears/"
|
||||
cp -v sdl2_gears "${COOKBOOK_STAGE}/usr/games/sdl2_gears/"
|
||||
"""
|
||||
@@ -0,0 +1,9 @@
|
||||
[source]
|
||||
git = "https://github.com/pop-os/winit.git"
|
||||
branch = "winit-0.29"
|
||||
|
||||
[build]
|
||||
template = "custom"
|
||||
script = """
|
||||
cookbook_cargo_examples cursor_grab drag_window window window_debug
|
||||
"""
|
||||
Reference in New Issue
Block a user