commit cedf7cac74958d1d10a86a852e4612aaaf7293f4 Author: Rusty Striker Date: Mon Jul 3 18:40:28 2023 +0300 first commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ca6f58a --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +build: + gcc mmn_17.c -lglut -lGL -lGLU -lm -o mmn_17 + +clean: + rm mmn_17 diff --git a/mmn_17.c b/mmn_17.c new file mode 100644 index 0000000..546184a --- /dev/null +++ b/mmn_17.c @@ -0,0 +1,37 @@ +#include +#include +#include +#include +#include + +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; +} \ No newline at end of file diff --git a/ui.c b/ui.c new file mode 100644 index 0000000..e69de29 diff --git a/ui.h b/ui.h new file mode 100644 index 0000000..b261947 --- /dev/null +++ b/ui.h @@ -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 \ No newline at end of file diff --git a/ui_button.h b/ui_button.h new file mode 100644 index 0000000..8719d9a --- /dev/null +++ b/ui_button.h @@ -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 \ No newline at end of file diff --git a/vec.c b/vec.c new file mode 100644 index 0000000..8438c4a --- /dev/null +++ b/vec.c @@ -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; +} \ No newline at end of file diff --git a/vec.h b/vec.h new file mode 100644 index 0000000..d558f03 --- /dev/null +++ b/vec.h @@ -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