Files
stgsharp/实验/GLenvTest/main.c
T

71 lines
2.3 KiB
C

#include "gl.h"
#include "glfw3.h"
#include "stdio.h"
#include "stdlib.h"
#include <stdbool.h>
#include "main.h"
void main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(800, 600, "Test", NULL, NULL);
if (window == NULL)
{
return -100;
}
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
glfwMakeContextCurrent(window);
context = malloc(sizeof(GladGLContext));
gladLoadGLContext(context, glfwGetProcAddress);
unsigned int shader = context->CreateShader(GL_VERTEX_SHADER);
const GLchar* code[] = { "Test string\0" };
context->ShaderSource(shader, 1, code, NULL);
printf("%s\n", code);
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
// render
// ------
context->ClearColor(0.2f, 0.3f, 0.3f, 1.0f);
context->Clear(GL_COLOR_BUFFER_BIT);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glfwSwapBuffers(window);
glfwPollEvents();
}
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
free(context);
return 0;
}
// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly
// ---------------------------------------------------------------------------------------------------------
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
// glfw: whenever the window size changed (by OS or user resize) this callback function executes
// ---------------------------------------------------------------------------------------------
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
// make sure the viewport matches the new window dimensions; note that width and
// height will be significantly larger than specified on retina displays.
context->Viewport(0, 0, width, height);
}