Add a fixed function program
This commit is contained in:
parent
ab928750cf
commit
86b72db39e
2 changed files with 62 additions and 1 deletions
60
src/fixedfunction.cc
Normal file
60
src/fixedfunction.cc
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <epoxy/gl.h>
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
void triangle() {
|
||||||
|
glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLES);
|
||||||
|
glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
|
glVertex3f(-1.0f, -1.0f, 0.0f);
|
||||||
|
|
||||||
|
glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
|
glVertex3f(0.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
|
glColor3f(0.0f, 0.0f, 1.0f);
|
||||||
|
glVertex3f(1.0f, -1.0f, 0.0f);
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
|
||||||
|
glViewport(0,0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
glfwInit();
|
||||||
|
|
||||||
|
// Set OpenGL version to 1.2.
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||||
|
|
||||||
|
// Create a GLFW window.
|
||||||
|
GLFWwindow* window = glfwCreateWindow(800, 600, "Fixed Function OpenGL 1.2", nullptr, nullptr);
|
||||||
|
|
||||||
|
// Fail if the window has failed to create.
|
||||||
|
if (window == nullptr) {
|
||||||
|
const char* description;
|
||||||
|
glfwGetError(&description);
|
||||||
|
std::cout << "Failed to create GLFW window.\n" << description << std::endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
glViewport(0,0, 800, 600);
|
||||||
|
|
||||||
|
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
|
||||||
|
|
||||||
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
triangle();
|
||||||
|
|
||||||
|
glfwSwapBuffers(window);
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -2,4 +2,5 @@ sources = [
|
||||||
'main.cc'
|
'main.cc'
|
||||||
]
|
]
|
||||||
|
|
||||||
exe = executable('main', sources, dependencies: [glfw, libepoxy])
|
executable('main', sources, dependencies: [glfw, libepoxy])
|
||||||
|
executable('fixedfunction', ['fixedfunction.cc'], dependencies: [glfw, libepoxy])
|
||||||
|
|
Loading…
Reference in a new issue