Commit f144adf6 authored by Bastian Krayer's avatar Bastian Krayer
Browse files

added first exercise

parent d1914b95
cmake_minimum_required(VERSION 3.1)
include(${CMAKE_MODULE_PATH}/DefaultExecutable.cmake)
\ No newline at end of file
CVK_2
\ No newline at end of file
#include <CVK_2/CVK_Framework.h>
#include <glad/glad.h>
#include <memory>
#include <random>
const int WIDTH = 600;
const int HEIGHT = 600;
const int NUM_POINTS = 50;
class Fragezeichen : public CVK::GlfwBase {
public:
Fragezeichen();
// run the actual loop and display
void display();
private:
};
int main() {
Fragezeichen demo;
demo.display();
return 0;
}
// Implementation
Fragezeichen::Fragezeichen() {
m_window = glfwCreateWindow(WIDTH, HEIGHT, "Voronoi", nullptr, nullptr);
// Allows us to associate data with a window
// We store a pointer to this object so we can use it in the static methods
glfwSetWindowUserPointer(m_window, this);
glfwSetWindowPos(m_window, 600, 50);
glfwMakeContextCurrent(m_window);
// init opengl
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
std::cerr << "Failed to initialize OpenGL context" << std::endl;
throw std::runtime_error("Failed to initialize OpenGL context");
}
}
void Fragezeichen::display() {
glClearColor(1, 1, 1, 1);
// create cone vao
// TODO Use appropriate constructor to create a cone with 45° opening angle,
// oriented along the z-axis with its apex located at (0,0,0). The height
// an be chosen to mach the camera's far value
// You can use the model matrix to move the geometry
CVK::Cone coneGeometry;
// TODO Generate random points and colors
// compile a shader program
CVK::ShaderSet shaderProgram(VERTEX_SHADER_BIT | FRAGMENT_SHADER_BIT,
{CVK::State::getInstance()->getShaderPath() +
"/Fragezeichen/fragezeichen.vert",
CVK::State::getInstance()->getShaderPath() +
"/Fragezeichen/fragezeichen.frag"});
// use the shader program
shaderProgram.useProgram();
// get uniform handles
GLint viewMatrixHandle =
glGetUniformLocation(shaderProgram.getProgramID(), "viewMatrix");
GLint projectionMatrixHandle =
glGetUniformLocation(shaderProgram.getProgramID(), "projectionMatrix");
GLint modelMatrixHandle =
glGetUniformLocation(shaderProgram.getProgramID(), "modelMatrix");
GLint colorHandle =
glGetUniformLocation(shaderProgram.getProgramID(), "color");
// setting up the camera parameters
glm::mat4 viewMatrix =
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.001f), glm::vec3(0.0f, 0.0f, 0.0f),
glm::vec3(0.0f, 1.0f, 0.0f));
glm::mat4 projectionMatrix =
glm::ortho(-1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 10.0f);
glm::mat4 modelMatrix = glm::mat4(1.0);
glUniformMatrix4fv(viewMatrixHandle, 1, GL_FALSE,
glm::value_ptr(viewMatrix));
glUniformMatrix4fv(projectionMatrixHandle, 1, GL_FALSE,
glm::value_ptr(projectionMatrix));
glUniformMatrix4fv(modelMatrixHandle, 1, GL_FALSE,
glm::value_ptr(modelMatrix));
// set color of the cone
glm::vec3 color(1.0, 0.0, 0.0);
glUniform3fv(colorHandle, 1, glm::value_ptr(color));
glEnable(GL_DEPTH_TEST);
// renderloop
while (!glfwWindowShouldClose(m_window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// TODO Render a cone for each point with the respective color
// render cone
coneGeometry.render();
glfwSwapBuffers(m_window);
glfwPollEvents();
}
}
#version 330 core
uniform vec3 color;
out vec4 fragmentColor;
void main() { fragmentColor = vec4(color, 1); }
\ No newline at end of file
#version 330 core
layout(location = 0) in vec4 position;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
uniform mat4 projectionMatrix;
void main() {
gl_Position = projectionMatrix * viewMatrix * modelMatrix * position;
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment