first commit

This commit is contained in:
Rusty Striker 2023-07-03 18:40:28 +03:00
commit cedf7cac74
Signed by: RustyStriker
GPG Key ID: 87E4D691632DFF15
7 changed files with 127 additions and 0 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
build:
gcc mmn_17.c -lglut -lGL -lGLU -lm -o mmn_17
clean:
rm mmn_17

37
mmn_17.c Normal file
View File

@ -0,0 +1,37 @@
#include <GL/freeglut.h>
#include <GL/freeglut_std.h>
#include <GL/gl.h>
#include <stdio.h>
#include <math.h>
void display(void) {
// Clear screen
glClearColor(0.0, 0.0, 0.0, 1.0); // Dark theme :)
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void mouseEvent(int button, int state, int x, int y) {
}
int main(int argc, char** argv) {
/* initialize glut and window */
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(800, 500);
glutInitWindowPosition(450, 450);
/* create window and set callbacks */
glutCreateWindow("glutLeaveMainLoop is undefined if called from a nested loop");
glutDisplayFunc(display);
glutMouseFunc(mouseEvent);
/* set projection and camera */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 800.0, 0.0, 500.0);
glutMainLoop();
return 0;
}

0
ui.c Normal file
View File

12
ui.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef __UI_BUTTON
#define __UI_BUTTON
#include "vec.h"
typedef struct _ui_button {
vec3 relative; // Position relative to screen size
vec3 absolute; // position in pixels(added to relative)
vec3 size; // size in pixels - if screen is too small i am not sure if it is a smart idea to make everything smaller
void (*onClick); // instead of passing stuff in, im just gonna put every state variable in global scope to ensure everything lives...
} ui_button;
#endif

25
ui_button.h Normal file
View File

@ -0,0 +1,25 @@
#ifndef __UI
#define __UI
#include "vec.h"
typedef struct _ui_position {
vec3 relative;
vec3 absolute;
} ui_pos;
typedef struct _ui_button {
ui_pos position;
/* x,y - width,height, z - unused */
vec3 size; // size in pixels - if screen is too small i am not sure if it is a smart idea to make everything smaller
void (*onClick); // instead of passing stuff in, im just gonna put every state variable in global scope to ensure everything lives...
char* text;
} ui_button;
typedef struct _ui_slider {
ui_pos position;
/* x - width, y - height, z - middle circle radius */
vec3 size;
float value; // Value will always range between 0 and 1
} ui_slider;
#endif

29
vec.c Normal file
View File

@ -0,0 +1,29 @@
#include "vec.h"
vec3 vec3_new(float x, float y, float z) {
vec3 r = { x, y, z };
return r;
}
vec3 vec3_splat(float f) {
vec3 r = { f, f, f };
return r;
}
vec3 vec3_add(vec3 a, vec3 b) {
vec3 r = { a.x + b.x, a.y + b.y, a.z + b.z };
return r;
}
vec3 vec3_sub(vec3 a, vec3 b) {
vec3 r = { a.x - b.x, a.y - b.y, a.z - b.z };
return r;
}
float vec3_dot(vec3 a, vec3 b) {
return a.x * b.x + a.y * b.y + a.z * b.z;
}
vec3 vec3_mult(vec3 a, float s) {
vec3 r = { a.x * s, a.y * s, a.z * s };
return r;
}

19
vec.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _VEC
#define _VEC
typedef struct _vec3 {
float x;
float y;
float z;
} vec3;
const vec3 ZERO = { 0.0, 0.0, 0.0};
vec3 vec3_new(float x, float y, float z);
vec3 vec3_splat(float f);
vec3 vec3_add(vec3 a, vec3 b);
vec3 vec3_sub(vec3 a, vec3 b);
float vec3_dot(vec3 a, vec3 b);
vec3 vec3_mult(vec3 a, float s);
#endif