Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
AG Computergrafik
ss21cg3
Commits
f144adf6
Commit
f144adf6
authored
Apr 14, 2021
by
Bastian Krayer
Browse files
added first exercise
parent
d1914b95
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/executables/Fragezeichen/CMakeLists.txt
0 → 100644
View file @
f144adf6
cmake_minimum_required
(
VERSION 3.1
)
include
(
${
CMAKE_MODULE_PATH
}
/DefaultExecutable.cmake
)
\ No newline at end of file
src/executables/Fragezeichen/dependencies.txt
0 → 100644
View file @
f144adf6
CVK_2
\ No newline at end of file
src/executables/Fragezeichen/main.cpp
0 → 100644
View file @
f144adf6
#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.0
f
,
0.0
f
,
0.001
f
),
glm
::
vec3
(
0.0
f
,
0.0
f
,
0.0
f
),
glm
::
vec3
(
0.0
f
,
1.0
f
,
0.0
f
));
glm
::
mat4
projectionMatrix
=
glm
::
ortho
(
-
1.0
f
,
1.0
f
,
-
1.0
f
,
1.0
f
,
0.0
f
,
10.0
f
);
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
();
}
}
src/shaders/Fragezeichen/fragezeichen.frag
0 → 100644
View file @
f144adf6
#version 330 core
uniform
vec3
color
;
out
vec4
fragmentColor
;
void
main
()
{
fragmentColor
=
vec4
(
color
,
1
);
}
\ No newline at end of file
src/shaders/Fragezeichen/fragezeichen.vert
0 → 100644
View file @
f144adf6
#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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment