Browse Source

first commit

IverMartinson 5 months ago
commit
a7f22d4dae

+ 6 - 0
.vscode/settings.json

@@ -0,0 +1,6 @@
+{
+    "files.associations": {
+        "functions.h": "c",
+        "sdl.h": "c"
+    }
+}

+ 13 - 0
Makefile

@@ -0,0 +1,13 @@
+COMPILER=gcc
+FLAGS_ALL=-g -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
+FLAGS_EXAMPLE=-Lbuild/ -lrasteriver -Wl,-rpath=build/ -lm -lSDL2
+FLAGS_LIB=-D CL_TARGET_OPENCL_VERSION=120 -fPIC -shared -lc -lSDL2 -lSDL2_ttf -lm -lOpenCL
+
+main.bin: rasteriver.so
+	$(COMPILER) $(FLAGS_ALL) src/launch_program/main.c -o build/main.bin $(FLAGS_EXAMPLE) 
+
+rasteriver.so:
+	$(COMPILER) $(FLAGS_ALL) src/library/rasteriver.c -o build/librasteriver.so $(FLAGS_LIB) 
+
+clean:
+	rm build/*

BIN
build/librasteriver.so


BIN
build/main.bin


+ 1 - 0
run

@@ -0,0 +1 @@
+./build/main.bin

+ 6 - 0
src/headers/custom_types.h

@@ -0,0 +1,6 @@
+#ifndef CUSTOM_TYPES_H
+#define CUSTOM_TYPES_H
+
+
+
+#endif

+ 8 - 0
src/headers/functions.h

@@ -0,0 +1,8 @@
+#ifndef FUNCTIONS_H
+#define FUNCTIONS_H
+
+int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title);
+int RI_stop(int result);
+int RI_tick();
+
+#endif

+ 28 - 0
src/headers/rasteriver.h

@@ -0,0 +1,28 @@
+#ifndef RASTERIVER_H
+#define RASTERIVER_H
+
+#include "functions.h"
+#include "values.h"
+#include <SDL2/SDL.h>
+
+typedef struct {
+    // rendering (non SDL)
+    int window_width;
+    int window_height;
+    char *window_title;
+
+    // SDL specific
+    uint32_t *frame_buffer;
+    SDL_Window *window;
+    SDL_Renderer *renderer;
+    SDL_Texture *texture;
+    SDL_Event event;
+    
+    // RasterIver
+
+    // miscellaneous
+    int running;
+    int frame;
+} RasterIver;
+
+#endif

+ 6 - 0
src/headers/values.h

@@ -0,0 +1,6 @@
+#ifndef VALUES_H
+#define VALUES_H
+
+
+
+#endif

+ 11 - 0
src/launch_program/main.c

@@ -0,0 +1,11 @@
+#include "../headers/rasteriver.h"
+
+int main(){
+    RI_init(800, 800, "This is RasterIver 2.0!!");
+
+    int running = 1;
+
+    while (running){
+        RI_tick();
+    }
+}

+ 74 - 0
src/library/rasteriver.c

@@ -0,0 +1,74 @@
+#include <CL/cl.h>
+#include <SDL2/SDL.h>
+#include "../headers/rasteriver.h"
+
+RasterIver ri;
+
+int RI_tick(){
+    // do rendering stuff
+    if (ri.running){
+        ri.frame_buffer[(ri.frame * 10) % (ri.window_width * ri.window_height)] += 100;
+
+        SDL_UpdateTexture(ri.texture, NULL, ri.frame_buffer, ri.window_width * sizeof(uint32_t));
+
+        SDL_RenderClear(ri.renderer);
+        SDL_RenderCopy(ri.renderer, ri.texture, NULL, NULL);
+    
+        SDL_RenderPresent(ri.renderer);
+    }
+    else{
+        RI_stop(0);
+    }
+
+    // handle SDL events
+    while (SDL_PollEvent(&ri.event))
+    {
+        switch (ri.event.type)
+        {
+        case SDL_QUIT:
+            ri.running = 0;
+        }
+    }
+
+    ++ri.frame;
+
+    return 0;
+}
+
+int opencl_init(){
+    return 0;
+}
+
+int sdl_init(int RI_window_width, int RI_window_height, char *RI_window_title){
+    ri.window_width = RI_window_width;
+    ri.window_height = RI_window_height;
+    ri.window_title = RI_window_title;
+
+    ri.frame_buffer = malloc(sizeof(uint32_t) * ri.window_width * ri.window_height);
+
+    SDL_Init(SDL_INIT_VIDEO);
+
+    ri.window = SDL_CreateWindow(RI_window_title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, ri.window_width, ri.window_height, SDL_WINDOW_OPENGL);
+
+    ri.renderer = SDL_CreateRenderer(ri.window, -1, SDL_RENDERER_ACCELERATED);
+
+    ri.texture = SDL_CreateTexture(ri.renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, ri.window_width, ri.window_height);
+
+    return 0;
+}
+
+int RI_init(int RI_window_width, int RI_window_height, char *RI_window_title){
+    ri.running = 1;
+
+    opencl_init();
+
+    sdl_init(RI_window_width, RI_window_height, RI_window_title);
+
+    return 0;
+}
+
+int RI_stop(int result){
+    exit(result);
+
+    return 0;
+}