add install target
This commit is contained in:
parent
7d230f2ccf
commit
2533289c24
7
Makefile
7
Makefile
|
@ -9,6 +9,8 @@ CFILES=$(shell cd src && find -L * -type f -name '*.c')
|
|||
OBJDIR=obj
|
||||
OBJ=$(addprefix $(OBJDIR)/, $(CFILES:.c=.o))
|
||||
|
||||
INSTALL_PREFIX=/usr/local
|
||||
|
||||
$(LIBRARY): $(OBJ) Makefile
|
||||
$(AR) rcs $(LIBRARY) $(OBJ)
|
||||
|
||||
|
@ -20,6 +22,11 @@ run: $(LIBRARY)
|
|||
make -C examples test
|
||||
cd examples && ./test
|
||||
|
||||
install: $(LIBRARY)
|
||||
cp $(LIBRARY) $(INSTALL_PREFIX)/lib
|
||||
mkdir -p $(INSTALL_PREFIX)/include/gearlib
|
||||
cp -r include/* $(INSTALL_PREFIX)/include
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ) $(LIBRARY)
|
||||
make -C examples clean
|
||||
|
|
|
@ -4,11 +4,11 @@ CFLAGS = -O3 -I../include
|
|||
LDFLAGS = -L ../ -lglfw -lgearlib -lm
|
||||
|
||||
CFILES=$(shell find -L * -type f -name '*.c')
|
||||
BINARIES=$(CFILES:.c=.exe)
|
||||
BINARIES=$(CFILES:.c=)
|
||||
|
||||
all: $(BINARIES)
|
||||
|
||||
%.exe: %.c
|
||||
%: %.c
|
||||
$(CC) $< -o $@ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
|
|
BIN
examples/quad
Executable file
BIN
examples/quad
Executable file
Binary file not shown.
39
examples/quad.c
Normal file
39
examples/quad.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <gearlib.h>
|
||||
|
||||
int main() {
|
||||
Window window = create_window(800, 600, "textures");
|
||||
glfwSwapInterval(0); // fps unlock
|
||||
setup_quads();
|
||||
|
||||
Camera* camera = create_camera(vec2(0.0f, 0.0f));
|
||||
UniformBuffer* camera_buffer = create_uniform_buffer(sizeof(CameraMatrices));
|
||||
|
||||
double time = glfwGetTime();
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
process_input(window);
|
||||
update_camera(camera, window);
|
||||
set_uniform_data(camera_buffer, camera->m);
|
||||
|
||||
glClearColor(vec4_spread(BLUE));
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
draw_quad(vec2(10, 10), vec2(500, 500), RED);
|
||||
|
||||
flush();
|
||||
|
||||
double end_time = glfwGetTime();
|
||||
double frame_time = end_time - time;
|
||||
time = end_time;
|
||||
|
||||
double fps = 1.0 / frame_time;
|
||||
printf("frame_time: %lf fps: %lf\n", frame_time, fps);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
BIN
examples/test
Executable file
BIN
examples/test
Executable file
Binary file not shown.
BIN
examples/textures
Executable file
BIN
examples/textures
Executable file
Binary file not shown.
|
@ -3,18 +3,19 @@
|
|||
|
||||
#define MAX_VERTICES 2500
|
||||
|
||||
#include <colors.h>
|
||||
#include <raymath.h>
|
||||
#include <init.h>
|
||||
#include <shaders.h>
|
||||
#include <events.h>
|
||||
#include <debugging.h>
|
||||
#include <vertex.h>
|
||||
#include <renderer.h>
|
||||
#include <camera.h>
|
||||
#include <batch.h>
|
||||
#include <quad.h>
|
||||
#include <textures.h>
|
||||
#include <uniform_buffer.h>
|
||||
#include <gearlib/slibs.h>
|
||||
#include <gearlib/colors.h>
|
||||
#include <gearlib/raymath.h>
|
||||
#include <gearlib/init.h>
|
||||
#include <gearlib/shaders.h>
|
||||
#include <gearlib/events.h>
|
||||
#include <gearlib/debugging.h>
|
||||
#include <gearlib/vertex.h>
|
||||
#include <gearlib/renderer.h>
|
||||
#include <gearlib/camera.h>
|
||||
#include <gearlib/batch.h>
|
||||
#include <gearlib/quad.h>
|
||||
#include <gearlib/textures.h>
|
||||
#include <gearlib/uniform_buffer.h>
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
#include <gearlib.h>
|
||||
#include <slibs.h>
|
||||
|
||||
typedef struct BatchStats {
|
||||
uint32_t draw_calls;
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __INIT_H__
|
||||
#define __INIT_H__
|
||||
|
||||
#include <opengl.h>
|
||||
#include <gearlib/opengl.h>
|
||||
|
||||
typedef GLFWwindow* Window;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __OPENGL_H__
|
||||
#define __OPENGL_H__
|
||||
|
||||
#include <glad/gl.h>
|
||||
#include <gearlib/glad/gl.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#endif
|
|
@ -11,12 +11,7 @@
|
|||
|
||||
#define sl_auto(name, x) typeof(x) name = x
|
||||
|
||||
#define sl_new(type, ...) \
|
||||
({ \
|
||||
type *ptr = malloc(sizeof(type)); \
|
||||
*ptr = (type){__VA_ARGS__}; \
|
||||
ptr; \
|
||||
})
|
||||
#define sl_new(type) calloc(sizeof(type), 1)
|
||||
|
||||
#define sl_init(type, ...) \
|
||||
(type) { __VA_ARGS__ }
|
10
src/batch.c
10
src/batch.c
|
@ -1,11 +1,10 @@
|
|||
#include <gearlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <slibs.h>
|
||||
|
||||
BatchList batches = { 0 };
|
||||
|
||||
RenderBatch* create_batch(size_t vert_size, uint32_t max_verts) {
|
||||
RenderBatch* batch = calloc(sizeof(RenderBatch), 1);
|
||||
RenderBatch* batch = sl_new(RenderBatch);
|
||||
sl_vec_push(batches, batch);
|
||||
|
||||
glCreateBuffers(1, &batch->vbo);
|
||||
|
@ -36,13 +35,6 @@ void flush_batch(RenderBatch* batch) {
|
|||
|
||||
glUseProgram(batch->shader);
|
||||
|
||||
/*glUniformMatrix4fv(0, 1, GL_FALSE,
|
||||
mat4ToFloat(mat4Multiply(batch->camera->view, batch->camera->projection)));*/
|
||||
|
||||
|
||||
//glUniformMatrix4fv(1, 1, GL_FALSE, mat4ToFloat(batch->camera->view));
|
||||
//glUniformMatrix4fv(2, 1, GL_FALSE, mat4ToFloat(batch->camera->projection));
|
||||
|
||||
if(batch->flush_callback != NULL)
|
||||
batch->flush_callback(batch);
|
||||
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
Camera* create_camera(vec2 pos) {
|
||||
Camera* camera = calloc(sizeof(Camera), 1);
|
||||
Camera* camera = sl_new(Camera);
|
||||
camera->position = vec3(pos, -3.0f);
|
||||
camera->m = calloc(sizeof(CameraMatrices), 1);
|
||||
camera->m = sl_new(CameraMatrices);
|
||||
|
||||
return camera;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ RenderBatch* create_texture_quad_batch() {
|
|||
compile_shader("assets/texture.vert", GL_VERTEX_SHADER),
|
||||
compile_shader("assets/texture.frag", GL_FRAGMENT_SHADER), 0);
|
||||
|
||||
texture_quad_batch->data = calloc(sizeof(TextureQuadBatchData), 1);
|
||||
texture_quad_batch->data = sl_new(TextureQuadBatchData);
|
||||
texture_quad_batch->flush_callback = &texture_flush_callback;
|
||||
|
||||
batch_add_attrib(texture_quad_batch, (VertexAttrib){
|
||||
|
|
Loading…
Reference in a new issue