Vulkan hard :(
This commit is contained in:
75
test/display/render.c
Normal file
75
test/display/render.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include "render.h"
|
||||
|
||||
render_t *RENDER_CURRENT = NULL;
|
||||
|
||||
render_t * renderInit(int32_t width, int32_t height, char *name) {
|
||||
// Can't contextualize twice
|
||||
if(RENDER_CURRENT != NULL) return NULL;
|
||||
|
||||
// Attempt to init GLFW
|
||||
if(!glfwInit()) return NULL;
|
||||
|
||||
// Initialize the renderer
|
||||
render_t *render = malloc(sizeof(render_t));
|
||||
if(!render) return NULL;
|
||||
render->width = width;
|
||||
render->height = height;
|
||||
|
||||
// Create the window.
|
||||
render->window = glfwCreateWindow(width, height, name, NULL, NULL);
|
||||
if(!render->window) {
|
||||
free(render);
|
||||
glfwTerminate();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Make the window the context current
|
||||
glfwMakeContextCurrent(render->window);
|
||||
RENDER_CURRENT = render;
|
||||
|
||||
// Listeners
|
||||
glfwSetWindowSizeCallback(render->window, &renderOnResize);
|
||||
|
||||
//GLEnable Things
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_TRUE);
|
||||
glDepthFunc(GL_LEQUAL);
|
||||
|
||||
return render;
|
||||
}
|
||||
|
||||
void renderFrame(render_t *render) {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
glColor3f(1, 0, 0);
|
||||
glVertex3f(-1, -1, 0);
|
||||
|
||||
glColor3f(0, 1, 0);
|
||||
glVertex3f(0, 1, 0);
|
||||
|
||||
glColor3f(0, 0, 1);
|
||||
glVertex3f(1, -1, 0);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
bool renderDispose(render_t *render) {
|
||||
// Cleanup the callback
|
||||
glfwSetWindowSizeCallback(render->window, NULL);
|
||||
|
||||
// Free up the renderer
|
||||
free(render);
|
||||
RENDER_CURRENT = NULL;
|
||||
|
||||
// Terminate the GLFW context.
|
||||
glfwTerminate();
|
||||
return true;
|
||||
}
|
||||
|
||||
void renderOnResize(GLFWwindow *window, int32_t width, int32_t height) {
|
||||
RENDER_CURRENT->width = width;
|
||||
RENDER_CURRENT->height = height;
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
62
test/display/render.h
Normal file
62
test/display/render.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <malloc.h>
|
||||
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <cglm/vec4.h>
|
||||
#include <cglm/mat4.h>
|
||||
|
||||
/**
|
||||
* Contains information about the current render state, can be used for querying
|
||||
* how the renderer is currently set up.
|
||||
*/
|
||||
typedef struct {
|
||||
/** The GLFW Window Context Pointer */
|
||||
GLFWwindow *window;
|
||||
|
||||
/** Resolution (in pixels) */
|
||||
int32_t width, height;
|
||||
} render_t;
|
||||
|
||||
/** Current active renderer. */
|
||||
extern render_t *RENDER_CURRENT;
|
||||
|
||||
/**
|
||||
* Initialize the renderer.
|
||||
*
|
||||
* @param width Width (in pixels) of the window.
|
||||
* @param height Height (in pixels) of the window.
|
||||
* @param name String of the windows' name.
|
||||
* @return Rendering Context information.
|
||||
*/
|
||||
render_t * renderInit(int32_t width, int32_t height, char *name);
|
||||
|
||||
/**
|
||||
* Render a single frame of the render loop. The renderer is not (currently)
|
||||
* responsible for render looping.
|
||||
*
|
||||
* @param render The renderer to loop for.
|
||||
*/
|
||||
void renderFrame(render_t *render);
|
||||
|
||||
/**
|
||||
* Cleanup a render context.
|
||||
*
|
||||
* @param render Renderer to cleanup.
|
||||
* @return True or False if Successful/Not.
|
||||
*/
|
||||
bool renderDispose(render_t *render);
|
||||
|
||||
/**
|
||||
* Resize callbacks.
|
||||
*
|
||||
* @param window Window that was resized.
|
||||
* @param width New window width.
|
||||
* @param height New window height.
|
||||
*/
|
||||
void renderOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
9
test/display/shader.c
Normal file
9
test/display/shader.c
Normal file
@ -0,0 +1,9 @@
|
||||
#include "shader.h"
|
||||
|
||||
shader_t * shaderCompile(char *vertexShaderSource, char* fragmentShaderSource) {
|
||||
}
|
||||
|
||||
|
||||
bool shaderDipose(shader_t *shader) {
|
||||
return true;
|
||||
}
|
36
test/display/shader.h
Normal file
36
test/display/shader.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
#include <GL/gl3w.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* Structure containing information about an OpenGL Shader. For simplicity sake
|
||||
* we demand certain uninforms to be present on the shader target.
|
||||
*/
|
||||
typedef struct {
|
||||
/** Pointer to an uploaded vertex shader program */
|
||||
unsigned int shaderVertex;
|
||||
|
||||
/** Pointer to an uploaded fragment shader program */
|
||||
unsigned int shaderFrag;
|
||||
|
||||
/** Pointer to an uploaded shader program linked */
|
||||
unsigned int shaderProgram;
|
||||
} shader_t;
|
||||
|
||||
/**
|
||||
* Create a shader from vertex and fragment shader code.
|
||||
*
|
||||
* @param vertexShaderSource The raw vertex shader code.
|
||||
* @param fragmentShaderSource The raw fragment shader code.
|
||||
* @return Pointer to the loaded shader.
|
||||
*/
|
||||
shader_t * shaderCompile(char *vertexShaderSource, char* fragmentShaderSource);
|
||||
|
||||
/**
|
||||
* Cleanup and unload a previously loaded shader.
|
||||
*
|
||||
* @param shader The shader to unload
|
||||
* @return True if successfully disposed.
|
||||
*/
|
||||
bool shaderDipose(shader_t *shader);
|
Reference in New Issue
Block a user