Loaded in shader source code from file
This commit is contained in:
parent
902d08847d
commit
420845fd87
3 changed files with 23 additions and 16 deletions
7
shaders/frag.glsl
Normal file
7
shaders/frag.glsl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
}
|
||||
8
shaders/vert.glsl
Normal file
8
shaders/vert.glsl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
|
||||
}
|
||||
|
||||
24
src/main.c
24
src/main.c
|
|
@ -9,26 +9,15 @@
|
|||
const unsigned int SCR_WIDTH = 800;
|
||||
const unsigned int SCR_HEIGHT = 600;
|
||||
|
||||
const char *vertexShaderSource =
|
||||
"#version 330 core\n"
|
||||
"layout (location = 0) in vec3 aPos;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
|
||||
"}\0";
|
||||
const char *fragmentShaderSource =
|
||||
"#version 330 core\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
|
||||
"}\n\0";
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_GLContext glcontext;
|
||||
SDL_Event event;
|
||||
|
||||
const char *vertexShaderSource = SDL_LoadFile("shaders/vert.glsl", NULL);
|
||||
const char *fragmentShaderSource = SDL_LoadFile("shaders/frag.glsl", NULL);
|
||||
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s",
|
||||
SDL_GetError());
|
||||
|
|
@ -47,7 +36,7 @@ int main(int argc, char *argv[]) {
|
|||
SDL_GetError());
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
SDL_GLContext glcontext = SDL_GL_CreateContext(window);
|
||||
glcontext = SDL_GL_CreateContext(window);
|
||||
if (!glcontext) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Couldn't create OpenGL Context: %s", SDL_GetError());
|
||||
|
|
@ -89,6 +78,9 @@ int main(int argc, char *argv[]) {
|
|||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Failed to compile fragment shader: %s", infoLog);
|
||||
}
|
||||
// Free source code memory
|
||||
SDL_free((void *)vertexShaderSource);
|
||||
SDL_free((void *)fragmentShaderSource);
|
||||
// link shaders
|
||||
unsigned int shaderProgram = glCreateProgram();
|
||||
glAttachShader(shaderProgram, vertexShader);
|
||||
|
|
|
|||
Loading…
Reference in a new issue