diff options
| -rw-r--r-- | CMakeLists.txt | 4 | ||||
| -rw-r--r-- | resources/shader.vertexshader | 4 | ||||
| -rw-r--r-- | shader.frag | 11 | ||||
| -rw-r--r-- | shader.vert | 23 | ||||
| -rw-r--r-- | src/main.c | 14 | ||||
| -rw-r--r-- | state_mainstate/include/states/mainstate.h | 8 | ||||
| -rw-r--r-- | state_mainstate/src/mainstate.c | 166 |
7 files changed, 216 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 32843ad..3964473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,4 +31,6 @@ daw_add_state(mainstate) add_executable(${PROJECT_NAME} src/main.c) target_link_libraries(${PROJECT_NAME} PUBLIC daw) -target_include_directories(${PROJECT_NAME} PUBLIC include) +target_include_directories(${PROJECT_NAME} PUBLIC include ${DAW_INCLUDE_DIRS}) + +get_target_property(LINKLIBS daw LINK_LIBRARIES) diff --git a/resources/shader.vertexshader b/resources/shader.vertexshader index 657053e..55b5250 100644 --- a/resources/shader.vertexshader +++ b/resources/shader.vertexshader @@ -13,5 +13,7 @@ void main() { gl_Position = MVP * vec4(vertexPosition_modelspace, 1); // gl_Position.w = 1.0; - fragmentcolor = vertexColor; + fragmentcolor.r = gl_position.x; //= vertexColor; + fragmentcolor.g = gl_position.y; //= vertexColor; + fragmentcolor.b = gl_position.z; //= vertexColor; } diff --git a/shader.frag b/shader.frag new file mode 100644 index 0000000..f81277d --- /dev/null +++ b/shader.frag @@ -0,0 +1,11 @@ +#version 330 core + +// Ouput data +in vec2 UV; +out vec3 color; + +uniform sampler2D textureSampler; + +void main() { + color = texture(textureSampler, UV).rgb; +} diff --git a/shader.vert b/shader.vert new file mode 100644 index 0000000..e5aff9a --- /dev/null +++ b/shader.vert @@ -0,0 +1,23 @@ +#version 330 core + +// Input vertex data, different for all executions of this shader. +layout(location = 0) in vec3 vertexPosition_modelspace; +layout(location = 1) in vec2 vertexUV; + +out vec2 UV; + +uniform mat4 MVP; + +void main() { + + gl_Position = MVP * vec4(vertexPosition_modelspace, 1); + + UV = vertexUV; + + //fragmentcolor.x = vertexPosition_modelspace.x; //= vertexColor; + //fragmentcolor.y = vertexPosition_modelspace.y; //= vertexColor; + //fragmentcolor.z = vertexPosition_modelspace.z; //= vertexColor; + + //fragmentcolor += 1; + //fragmentcolor /= 2; +} @@ -1,17 +1,15 @@ #include <engine/engine.h> -#include <rogue/resources.h> +#include <engine/core/logging.h> #define MEMORY_SIZE 65536 int main(void) { - Platform *p = engine_init("rogue", - 0,0, - 1.f, 0, - MEMORY_SIZE, - NULL, - NULL); + Platform *p = engine_init("rogue", + 420, 420, + 1.f, 0, + MEMORY_SIZE); - engine_run(p, STATE_titlescreen); + engine_run(p, STATE_mainstate, NULL); engine_stop(p); } diff --git a/state_mainstate/include/states/mainstate.h b/state_mainstate/include/states/mainstate.h index 1abfa67..042550f 100644 --- a/state_mainstate/include/states/mainstate.h +++ b/state_mainstate/include/states/mainstate.h @@ -2,12 +2,20 @@ #define STATE_TITLESCREEN_H #include <stdbool.h> +#include <engine/core/types.h> +#include <engine/rendering/rendering.h> +#include <engine/resources.h> //#include <engine/state.h> //#include <engine/engine.h> //#include <engine/ui.h> //#include <engine/input.h> typedef struct mainstate_state { + /* Resources */ + Shader shaders[10]; + RenderObject objects[10]; + Resources resources; + f64 height; } mainstate_state; #endif diff --git a/state_mainstate/src/mainstate.c b/state_mainstate/src/mainstate.c index e9d6dec..151319c 100644 --- a/state_mainstate/src/mainstate.c +++ b/state_mainstate/src/mainstate.c @@ -1,16 +1,174 @@ -//#include <engine/logging.h> -//#include <engine/input.h> +#include <engine/engine.h> +#include <engine/core/logging.h> +#include <engine/rendering/rendering.h> #include <states/mainstate.h> +#include <engine/core/state.h> +#include <cglm/cglm.h> -void mainstate_init(mainstate_state *state) { +enum GameResources { + MyVertexShader, + MyFragmentShader, + MyDefaultShader, +}; + +void mainstate_init(mainstate_state *state, void* arg) { INFO("Starting mainstate"); + + // Use the INDICES of the assets to specify the shaders to be composed + static u32 default_shader[] = {MyVertexShader, MyFragmentShader}; + + /* 0. Declare resources */ + static asset_t mainstate_assets[] = { + [MyVertexShader] = Declare_Shader("shader.vert"), + [MyFragmentShader] = Declare_Shader("shader.frag"), + [MyDefaultShader] = Declare_ShaderProgram(default_shader, sizeof(default_shader) / sizeof(default_shader[0])), + }; + + + state->resources.assets = mainstate_assets; + state->resources.assets_len = sizeof(mainstate_assets) / sizeof(mainstate_assets[0]); + LOG("RES LEN: %lu", state->resources.assets_len); + + /* 1. Load resources */ + resources_load(&state->resources); + + // TODO: Fixup this mess below: + static f32 crate[] = { + -1.0f, -1.0f, -1.0f, // triangle 1 : begin + -1.0f, -1.0f, 1.0f, + -1.0f, 1.0f, 1.0f, // triangle 1 : end + 1.0f, 1.0f, -1.0f, // triangle 2 : begin + -1.0f, -1.0f, -1.0f, + -1.0f, 1.0f, -1.0f, // triangle 2 : end + 1.0f, -1.0f, 1.0f, + -1.0f, -1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + -1.0f, -1.0f, -1.0f, + -1.0f, -1.0f, -1.0f, + -1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, -1.0f, + 1.0f, -1.0f, 1.0f, + -1.0f, -1.0f, 1.0f, + -1.0f, -1.0f, -1.0f, + -1.0f, 1.0f, 1.0f, + -1.0f, -1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, 1.0f, -1.0f, + 1.0f, -1.0f, -1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, -1.0f, + -1.0f, 1.0f, -1.0f, + 1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, -1.0f, + -1.0f, 1.0f, 1.0f, + 1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, 1.0f, + 1.0f, -1.0f, 1.0f + }; + + + static f32 uv[] = { + 0.0, 1.0, + 1.0, 1.0, + 1.0, 0.0, + //0.000059f, 1.0f-0.000004f, + //0.000103f, 1.0f-0.336048f, + //0.335973f, 1.0f-0.335903f, + + 0.0, 0.0, + 1.0, 1.0, + 1.0, 0.0, + //1.000023f, 1.0f-0.000013f, + //0.667979f, 1.0f-0.335851f, + //0.999958f, 1.0f-0.336064f, + + 0.667979f, 1.0f-0.335851f, + 0.336024f, 1.0f-0.671877f, + 0.667969f, 1.0f-0.671889f, + + 0.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, + //1.000023f, 1.0f-0.000013f, + //0.668104f, 1.0f-0.000013f, + //0.667979f, 1.0f-0.335851f, + + 0.0, 1.0, + 1.0, 0.0, + 0.0, 0.0, + //0.000059f, 1.0f-0.000004f, + //0.335973f, 1.0f-0.335903f, + //0.336098f, 1.0f-0.000071f, + + 0.0, 1.0, + 1.0, 0.0, + 0.0, 0.0, + //0.667979f, 1.0f-0.335851f, + //0.335973f, 1.0f-0.335903f, + //0.336024f, 1.0f-0.671877f, + + 0.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, + //1.000004f, 1.0f-0.671847f, + //0.999958f, 1.0f-0.336064f, + //0.667979f, 1.0f-0.335851f, + + 0.0, 0.0, + 1.0, 1.0, + 1.0, 0.0, + //0.668104f, 1.0f-0.000013f, + //0.335973f, 1.0f-0.335903f, + //0.667979f, 1.0f-0.335851f, + + 1.0, 1.0, + 0.0, 0.0, + 0.0, 1.0, + //0.335973f, 1.0f-0.335903f, + //0.668104f, 1.0f-0.000013f, + //0.336098f, 1.0f-0.000071f, + + 0.000103f, 1.0f-0.336048f, + 0.000004f, 1.0f-0.671870f, + 0.336024f, 1.0f-0.671877f, + + 0.000103f, 1.0f-0.336048f, + 0.336024f, 1.0f-0.671877f, + 0.335973f, 1.0f-0.335903f, + + 1.0, 0.0, + 0.0, 0.0, + 1.0, 1.0, + //0.667969f, 1.0f-0.671889f, + //1.000004f, 1.0f-0.671847f, + //0.667979f, 1.0f-0.335851f + }; + + + // + state->objects[0] = RenderObject_new(crate, get_asset(&state->resources, MyDefaultShader), sizeof(crate), uv, sizeof(uv)); + + // Setup controls + } -void mainstate_free(mainstate_state *state) { +void* mainstate_free(mainstate_state *state) { + return NULL; } StateType mainstate_update(mainstate_state *state) { StateType next_state = STATE_null; + vec3 pos = {0.f, 0.f}; + engine_draw_model(&(state->objects[0]), pos); + vec3 pos2 = {3.5f, 0.0f, 0.5f}; + engine_draw_model(&(state->objects[0]), pos2); + return next_state; } |
