create framebuffer object

This commit is contained in:
Gregory Wells
2025-08-18 23:02:56 -04:00
parent 51bd6e28fa
commit 453f7b70db
4 changed files with 66 additions and 3 deletions

View File

@@ -11,6 +11,7 @@
#include "framebuffer/opengl_framebuffer.h"
#include "graphics_pipeline/opengl_graphics_pipeline.h"
#include "submit/opengl_submit.h"
#include "present/opengl_present.h"
gnDeviceFunctions loadOpenGLDeviceFunctions() {
return (gnDeviceFunctions){
@@ -53,7 +54,7 @@ gnDeviceFunctions loadOpenGLDeviceFunctions() {
._gnDestroyTexture = openglDestroyTexture,
._gnSubmit = openglSubmit,
._gnPresent = NULL,
._gnPresent = openglPresent,
._gnWaitForDevice = waitForOpenGLDevice
};

View File

@@ -0,0 +1,22 @@
const char * vertex_shader_source =
"#version 450 core"
""
"layout(location = 0) in vec2 inPosition;"
"layout(location = 1) in vec2 inTexcoord;"
""
"out vec2 texcoord;"
""
"void main() {"
" gl_Position = vec4(inPosition, 0.0, 1.0);"
" texcoord = inTexcoord;"
"}" ;
const char * fragment_shader_source =
"#version 450 core"
""
"out vec4 FragColor;"
"layout(binding = 0) uniform sampler2D tex;"
"in vec2 texcoord;"
""
"void main() {"
" FragColor = texture(tex, texcoord);"
"}" ;

View File

@@ -1,5 +1,43 @@
#include "glad/glad.h"
#include "opengl_output_device.h"
#include "glsl_shader.glsl"
#include "stdlib.h"
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) { return GN_SUCCESS; }
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo) {
device->outputDevice = malloc(sizeof(gnPlatformOutputDevice));
float vertices[] = {
-1.0f, -1.0f, 0.0f, 1.0f,
1.0f, -1.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f, 0.0f,
};
glCreateBuffers(1, &device->outputDevice->buffer);
glBindBuffer(GL_ARRAY_BUFFER, device->outputDevice->buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)(sizeof(float) * 2));
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0);
unsigned int vertexShader;
vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &vertex_shader_source, NULL);
glCompileShader(vertexShader);
unsigned int fragmentShader;
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &fragment_shader_source, NULL);
glCompileShader(fragmentShader);
device->outputDevice->shaderProgram = glCreateProgram();
glAttachShader(device->outputDevice->shaderProgram, vertexShader);
glAttachShader(device->outputDevice->shaderProgram, fragmentShader);
glLinkProgram(device->outputDevice->shaderProgram);
return GN_SUCCESS;
}
void waitForOpenGLDevice(const gnOutputDeviceHandle device) {}
void destroyOpenGLOutputDevice(gnOutputDeviceHandle device) {}

View File

@@ -1,7 +1,9 @@
#pragma once
#include <output_device/gryphn_output_device.h>
typedef struct gnPlatformOutputDevice_t {} gnPlatformOutputDevice;
typedef struct gnPlatformOutputDevice_t {
unsigned int buffer, shaderProgram;
} gnPlatformOutputDevice;
gnReturnCode createOpenGLOutputDevice(gnInstanceHandle instance, gnOutputDeviceHandle device, gnOutputDeviceInfo deviceInfo);
void waitForOpenGLDevice(const gnOutputDeviceHandle device);