file reading
This commit is contained in:
parent
bfb53024e2
commit
652d9fa921
2 changed files with 25 additions and 14 deletions
|
|
@ -1,3 +1,9 @@
|
|||
void main() {
|
||||
gl_FragColor = vec4(1.0,0.0,1.0,1.0);
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
in vec2 uv;
|
||||
uniform vec2 WindowSize;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);
|
||||
}
|
||||
|
|
|
|||
29
main.c
29
main.c
|
|
@ -1,6 +1,7 @@
|
|||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <GL/gl.h>
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
|
|
@ -11,17 +12,6 @@ void checkGlError() {
|
|||
}
|
||||
}
|
||||
|
||||
const char *fragment_shader_source =
|
||||
"#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"in vec2 uv;\n"
|
||||
"uniform vec2 WindowSize;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
GLuint compile_shader(GLuint type, const char *src) {
|
||||
GLuint id = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
glShaderSource(id, 1, &src, 0);
|
||||
|
|
@ -55,6 +45,21 @@ GLuint create_shader(const char *fragment_src) {
|
|||
return program;
|
||||
}
|
||||
|
||||
GLuint load_shader(const char *path) {
|
||||
FILE *handle = fopen(path, "r");
|
||||
fseek(handle, 0L, SEEK_END);
|
||||
long length = ftell(handle);
|
||||
fseek(handle, 0L, SEEK_SET);
|
||||
char *string = malloc(length * sizeof(char));
|
||||
fread(string, sizeof(char), length, handle);
|
||||
fclose(handle);
|
||||
|
||||
GLuint shader = create_shader(string);
|
||||
|
||||
free(string);
|
||||
return shader;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Good Morning 🍵\n");
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
|
@ -79,7 +84,7 @@ int main() {
|
|||
int running = 1;
|
||||
float angle = 0.0;
|
||||
|
||||
GLuint shader = create_shader(fragment_shader_source);
|
||||
GLuint shader = load_shader("fragment.glsl"); //create_shader(fragment_shader_source);
|
||||
glUseProgram(shader);
|
||||
|
||||
int w, h;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue