aboutsummaryrefslogtreecommitdiff
path: root/opengl.c
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2023-11-09 02:17:39 +0100
committerNathan Reiner <nathan@nathanreiner.xyz>2023-11-09 02:17:39 +0100
commit87a70d198b1361b6c9601e61fef6b58071bbd0a8 (patch)
tree4984b93437a13d6f9fac8876e9e39cf0a78bbebb /opengl.c
parent0dca2c3e51c98dfa9e62cddd32cadbf6c7f71a3d (diff)
add interactivity and shared libHEADv0.0.1master
Diffstat (limited to 'opengl.c')
-rw-r--r--opengl.c138
1 files changed, 0 insertions, 138 deletions
diff --git a/opengl.c b/opengl.c
deleted file mode 100644
index 2b0b70c..0000000
--- a/opengl.c
+++ /dev/null
@@ -1,138 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/time.h>
-#include <math.h>
-
-#include <GL/freeglut.h>
-
-void draw_axis() {
- glColor3f(1, 1, 1);
- glBegin(GL_LINES);
-
- glVertex2f(0, 0);
- glVertex2f(1, 0);
- glVertex2f(0, 0);
- glVertex2f(0, 1);
-
- glVertex2f(1, 0);
- glVertex2f(0.9, 0.1);
- glVertex2f(1, 0);
- glVertex2f(0.9, -0.1);
-
- glVertex2f(0, 1);
- glVertex2f(0.1, 0.9);
- glVertex2f(0, 1);
- glVertex2f(-0.1, 0.9);
-
- glEnd();
-}
-
-void draw_grid() {
- glColor3f(0.2, 0.2, 0.2);
-
- glBegin(GL_LINES);
-
- for (int i = -10; i < 10; ++i) {
- glVertex2f(i, -10);
- glVertex2f(i, 10);
- }
-
- for (int i = -10; i < 10; ++i) {
- glVertex2f(-10, i);
- glVertex2f(10, i);
- }
-
- glEnd();
-
- glColor3f(0.5, 0.5, 0.5);
-
- glBegin(GL_LINES);
-
- glVertex2f(-10, 0);
- glVertex2f(10, 0);
-
- glVertex2f(0, -10);
- glVertex2f(0, 10);
-
- glEnd();
-}
-
-void draw_function(double from, double to, double step, double(*fun)(double)) {
- glColor3f(0.9f, 0.5f, 0.2f);
- glLineWidth(2);
- glBegin(GL_LINES);
-
- for (float i = from; i < to; i += step) {
- double current = fun(i);
- double next = fun(i + step);
-
- glVertex2f(i, current);
- glVertex2f(i + step, next);
- }
-
- glEnd();
-}
-
-double tp(double x, double a, double b, double c, double d) {
- return a * x * x * x + b * x * x + c * x + d;
-}
-
-double example_function(double x) {
- return tp(x, 1, 5, 5, -1);
-}
-
-static void display(void) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-
- draw_grid();
- draw_axis();
- draw_function(-10, 10, 0.01, &example_function);
-
- glutSwapBuffers();
-}
-
-static void keyboard(unsigned char key, int x, int y) {
- printf("Pressed %c key\n", key);
- if(key == 'q') {
- exit(0);
- }
-}
-
-void enableMultisample(int msaa) {
- if (msaa) {
- glEnable(GL_MULTISAMPLE);
- glHint(GL_MULTISAMPLE_FILTER_HINT_NV, GL_NICEST);
-
- // detect current settings
- GLint iMultiSample = 0;
- GLint iNumSamples = 0;
- glGetIntegerv(GL_SAMPLE_BUFFERS, &iMultiSample);
- glGetIntegerv(GL_SAMPLES, &iNumSamples);
- printf("MSAA on, GL_SAMPLE_BUFFERS = %d, GL_SAMPLES = %d\n", iMultiSample, iNumSamples);
- } else {
- glDisable(GL_MULTISAMPLE);
- printf("MSAA off\n");
- }
-}
-
-int main(int argc, char **argv) {
- glutInit(&argc, argv);
- glutInitWindowSize(600, 600);
- glutSetOption(GLUT_MULTISAMPLE, 8);
- glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
- glutCreateWindow("cme");
-
- enableMultisample(1);
-
- printf("OpenGL version = %s\n", glGetString(GL_VERSION));
-
- glutDisplayFunc(display);
- glutKeyboardFunc(keyboard);
-
- glScalef(0.1, 0.1, 0.1);
- glClearColor(0.0, 0.0, 0.0, 1.0);
-
-
- glutMainLoop();
-}