window size unform
This commit is contained in:
parent
c118d92fa7
commit
bfb53024e2
1 changed files with 11 additions and 2 deletions
13
main.c
13
main.c
|
|
@ -15,10 +15,11 @@ 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 / 800, 0.0, 1.0);\n"
|
||||
" FragColor = vec4(gl_FragCoord.xy / WindowSize, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
GLuint compile_shader(GLuint type, const char *src) {
|
||||
|
|
@ -81,14 +82,22 @@ int main() {
|
|||
GLuint shader = create_shader(fragment_shader_source);
|
||||
glUseProgram(shader);
|
||||
|
||||
int w, h;
|
||||
while (running) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
if (e.type == SDL_EVENT_QUIT) running = false;
|
||||
if (e.type == SDL_EVENT_WINDOW_RESIZED) {
|
||||
SDL_GetWindowSize(window, &w, &h);
|
||||
}
|
||||
}
|
||||
checkGlError();
|
||||
|
||||
// Rendorrrr
|
||||
glViewport(0, 0, 800, 800);
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
int uniform_WindowSize = glGetUniformLocation(shader, "WindowSize");
|
||||
glUniform2f(uniform_WindowSize, w, h);
|
||||
|
||||
glClearColor(0.1f, 0.1f, 0.1f, 1.0f); // Dark gray background
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue