Compare commits

...

10 Commits

Author SHA1 Message Date
Lexxy Fox
f42d103756 make run now vsyncs 2023-11-02 13:18:39 -05:00
Lexxy Fox
a745831c14 switched --help to lowercase 2023-11-02 13:03:18 -05:00
Lexxy Fox
8404b1695c added --version manually
I can't get argp_program_version working...
2023-11-02 13:02:33 -05:00
Lexxy Fox
a32edb4eec code format 2023-11-02 12:41:08 -05:00
Lexxy Fox
e970b2f661 added command line parameter to set spin speed 2023-11-02 11:41:51 -05:00
Lexxy Fox
c32f4bdf09 remove out.txt 2023-11-02 10:43:59 -05:00
Lexxy Fox
4043a6b6ab added h1 to readme 2023-11-02 10:13:27 -05:00
Lexxy Fox
7fa54e80a5 merged glut_wrap.h into glxgears
I saw a post yesterday where someone had made a similar fork and they left out glut_wrap.h for unknown reasons and they had ~dozen people involved, so I'm following suit. (peer pressure ftw)
2023-11-02 10:09:26 -05:00
Lexxy Fox
bf9578a97a beta argp code 2023-11-01 18:29:30 -05:00
Lexxy Fox
086060b9f5 refactor arg parsing 2023-11-01 16:55:02 -05:00
6 changed files with 112 additions and 1533 deletions

View File

@@ -13,6 +13,7 @@ ReflowComments: true
RemoveBracesLLVM: true
SortIncludes: CaseInsensitive
TabWidth: 2
ContinuationIndentWidth: 2
UseTab: AlignWithSpaces
# ex:se ft=yaml

View File

@@ -1,4 +1,5 @@
VERSION ?= 9.0.1
# Options (e.g. `CFLAGS=-DHAVE_ARGP make`)
# HAVE_ARGP: use `argp` for argument parsing.
prefix ?= /usr/local
exec_prefix ?= $(prefix)
@@ -16,7 +17,6 @@ RM ?= rm -f
CPPFLAGS := \
-D_FORTIFY_SOURCE=2 \
-DVERSION=$(VERSION) \
$(CPPFLAGS)
OFLAGS := -O3 \
-falign-functions=1 \
@@ -37,6 +37,7 @@ WFLAGS := \
-Wextra \
-Wformat-security \
-Wno-ignored-optimization-argument \
-Wno-missing-field-initializers \
-Wno-unknown-warning-option \
-Wsuggest-attribute=const \
-Wsuggest-attribute=format \
@@ -70,7 +71,7 @@ all: glxgears
-include glxgears.d
run: glxgears
vblank_mode=0 __GL_SYNC_TO_VBLANK=0 ./$<
./$<
clean:
$(RM) glxgears glxgears.i glxgears.s glxgears.o
@@ -90,4 +91,4 @@ uninstall:
# https://www.gnu.org/prep/standards/html_node/Directory-Variables.html
# https://www.gnu.org/prep/standards/html_node/Standard-Targets.html
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
# https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
# https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

View File

@@ -1,3 +1,5 @@
# Lexxy's GLXGears
<img src="https://lexxyfox.codeberg.page/glxgears/glxgears.gif" width="300" height="300">
(TODO: actual readme)

View File

@@ -1,11 +0,0 @@
#ifdef HAVE_FREEGLUT
#include <GL/freeglut.h>
#elif defined __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#ifndef GLAPIENTRY
#define GLAPIENTRY
#endif

View File

@@ -12,12 +12,24 @@
* Other modifications by Lexxy Fox.
*/
#ifdef HAVE_ARGP
#include <argp.h>
#endif
#include <GL/gl.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#ifdef HAVE_FREEGLUT
#include <GL/freeglut.h>
#elif defined __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include "glut_wrap.h"
#ifndef GLAPIENTRY
#define GLAPIENTRY
#endif
static GLint T0 = 0;
static GLint Frames = 0;
@@ -39,11 +51,11 @@ static GLfloat viewDist = 40.0;
**/
static void gear(
GLfloat inner_radius,
GLfloat outer_radius,
GLfloat width,
GLint teeth,
GLfloat tooth_depth
GLfloat inner_radius,
GLfloat outer_radius,
GLfloat width,
GLint teeth,
GLfloat tooth_depth
) {
GLint i;
GLfloat r0, r1, r2;
@@ -69,7 +81,7 @@ static void gear(
if (i < teeth) {
glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), width * 0.5
);
}
}
@@ -98,7 +110,7 @@ static void gear(
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
if (i < teeth) {
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
);
glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
}
@@ -112,10 +124,10 @@ static void gear(
angle = i * 2.0 * M_PI / teeth;
glVertex3f(
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
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
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);
@@ -140,14 +152,14 @@ static void gear(
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
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
r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da), -width * 0.5
);
glNormal3f(cos(angle), sin(angle), 0.0);
}
@@ -174,7 +186,7 @@ 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 void cleanup(void) {
static void __attribute__((noreturn)) cleanup(void) {
glDeleteLists(gear1, 1);
glDeleteLists(gear2, 1);
glDeleteLists(gear3, 1);
@@ -230,6 +242,8 @@ static void draw(void) {
}
}
static GLfloat rotation_speed = 70.0;
static void idle(void) {
static double t0 = -1.;
double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
@@ -238,8 +252,8 @@ static void idle(void) {
dt = t - t0;
t0 = t;
angle += 70.0 * dt; /* 70 degrees per second */
angle = fmod(angle, 360.0); /* prevents eventual overflow */
angle += rotation_speed * dt; /* 70 degrees per second */
angle = fmod(angle, 360.0); /* prevents eventual overflow */
glutPostRedisplay();
}
@@ -310,6 +324,8 @@ static void reshape(int width, int height) {
glMatrixMode(GL_MODELVIEW);
}
static GLboolean print_glinfo = GL_FALSE;
static void init_scene(void) {
glLightfv(GL_LIGHT0, GL_POSITION, (const GLfloat[]){5.0, 5.0, 10.0, 0.0});
glEnable(GL_CULL_FACE);
@@ -321,9 +337,9 @@ static void init_scene(void) {
gear1 = glGenLists(1);
glNewList(gear1, GL_COMPILE);
glMaterialfv(
GL_FRONT,
GL_AMBIENT_AND_DIFFUSE,
(const GLfloat[]){245.0 / 255, 169.0 / 255, 184.0 / 255, 1}
GL_FRONT,
GL_AMBIENT_AND_DIFFUSE,
(const GLfloat[]){245.0 / 255, 169.0 / 255, 184.0 / 255, 1}
);
gear(1.0, 4.0, 1.0, 20, 0.7);
glEndList();
@@ -337,14 +353,22 @@ static void init_scene(void) {
gear3 = glGenLists(1);
glNewList(gear3, GL_COMPILE);
glMaterialfv(
GL_FRONT,
GL_AMBIENT_AND_DIFFUSE,
(const GLfloat[]){91.0 / 255, 206.0 / 255, 250.0 / 255, 1}
GL_FRONT,
GL_AMBIENT_AND_DIFFUSE,
(const GLfloat[]){91.0 / 255, 206.0 / 255, 250.0 / 255, 1}
);
gear(1.3, 2.0, 0.5, 10, 0.7);
glEndList();
glEnable(GL_NORMALIZE);
if (print_glinfo) {
printf("GL_VENDOR = %s\n", (char *)glGetString(GL_VENDOR));
printf("GL_RENDERER = %s\n", (char *)glGetString(GL_RENDERER));
printf("GL_VERSION = %s\n", (char *)glGetString(GL_VERSION));
printf("GL_EXTENSIONS = %s\n", (char *)glGetString(GL_EXTENSIONS));
fflush(stdout);
}
}
static void visible(int vis) {
@@ -354,24 +378,71 @@ static void visible(int vis) {
static char *window_title = "Gears";
static void parse_args(int argc, char *argv[]) {
for (GLint i = 1; i < argc; i++)
if (strcmp(argv[i], "-info") == 0) {
printf("GL_VENDOR = %s\n", (char *)glGetString(GL_VENDOR));
printf("GL_RENDERER = %s\n", (char *)glGetString(GL_RENDERER));
printf("GL_VERSION = %s\n", (char *)glGetString(GL_VERSION));
printf("GL_EXTENSIONS = %s\n", (char *)glGetString(GL_EXTENSIONS));
fflush(stdout);
} else if (strcmp(argv[i], "-exit") == 0) {
#ifdef HAVE_ARGP
static const struct argp_option options[] = {
{"version", 'V', 0, 0, "print program version"},
{"info", 256, 0, 0, "display OpenGL renderer information"},
{"exit", 257, 0, 0, "automatically exit after 30 seconds"},
{"noanim", 258, 0, 0, "don't start animation"},
{"spin",
259,
"speed",
0,
"set rotational speed in RPM (defaults to 11.666666667)"},
{"title", 260, "title", 0, "set window title (defaults to \"Gears\")"},
{0}};
static error_t parse_opt(int key, char *val, struct argp_state *) {
switch (key) {
case 'V':
printf("glxgears 9.0.1\n");
exit(EXIT_SUCCESS);
case 256:
print_glinfo = GL_TRUE;
break;
case 257:
autoexit = 30;
printf("Auto Exit after %i seconds.\n", autoexit);
fflush(stdout);
} else if (strcmp(argv[i], "-noanim") == 0)
break;
case 258:
Animate = GL_FALSE;
break;
case 259:
rotation_speed = atof(val) * 6;
break;
case 260:
window_title = val;
break;
}
return 0;
}
static const struct argp argp = {
options,
parse_opt,
0,
"The glxgears program is a port of the `gears` demo to GLX. It displays a "
"set of rotating gears and prints out the frame rate at regular intervals. "
"It has become quite popular as basic benchmarking tool."};
#else
static void parse_args(int argc, char *argv[]) {
for (GLint i = 1; i < argc; i++)
if (strcmp(argv[i], "-exit") == 0) {
autoexit = 30;
printf("Auto exiting after %i seconds.\n", autoexit);
fflush(stdout);
} else if (strcmp(argv[i], "-info") == 0)
print_glinfo = GL_TRUE;
else if (strcmp(argv[i], "-noanim") == 0)
Animate = GL_FALSE;
}
#endif
int main(int argc, char *argv[]) {
#ifdef HAVE_ARGP
argp_parse(&argp, argc, argv, ARGP_LONG_ONLY, 0, 0);
#else
parse_args(argc, argv);
#endif
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
win = glutCreateWindow(window_title);

1485
out.txt

File diff suppressed because it is too large Load Diff