Compare commits

...

1 Commits
main ... u03-3

Author SHA1 Message Date
Luca Conte 7b28b5621f u03-3 2025-03-11 11:41:26 +01:00
2 changed files with 15 additions and 116 deletions

View File

@ -22,6 +22,8 @@ GLuint initialWindowHeight = 600;
int frameCount = 0; int frameCount = 0;
struct timespec last_time, current_time; struct timespec last_time, current_time;
unsigned int resolution = 50;
typedef struct ColorRGB { typedef struct ColorRGB {
GLfloat r; GLfloat r;
GLfloat g; GLfloat g;
@ -106,105 +108,17 @@ void init(void) {
INFO("Shader Program Done."); INFO("Shader Program Done.");
// create triangle buffer GLfloat innerRadius = 0.2f;
/** GLfloat outerRadius = 0.8f;
* -0.35 0.35
* | -0.2 0.2 |
* | | | |
*
* +----+ +----+ --- 0.6
* | | | |
* | | | |
* | +--------+ | --- 0.1
* | |
* | +--------+ | --- -0.1
* | | | |
* | | | |
* +----+ +----+ --- -0.6
*
* +------------------+ --- -0.7
* | |
* +------------------+ --- -0.9
*
*/
GLfloat vertices[] = { GLfloat vertices[(resolution + 1) * 2 * 2];
// X // Y for (unsigned int i = 0; i <= resolution; i++) {
GLfloat angle = ((float)i) / resolution * 2 * M_PI;
// left vertical bar vertices[4 * i + 0] = innerRadius * cos(angle);
-0.35f, -0.6f, vertices[4 * i + 1] = innerRadius * sin(angle);
-0.35f, 0.6f, vertices[4 * i + 2] = outerRadius * cos(angle);
-0.2f, 0.6f, vertices[4 * i + 3] = outerRadius * sin(angle);
}
-0.35f, -0.6f,
-0.2f, 0.6f,
-0.2f, -0.6f,
// right vertical bar
0.35f, -0.6f,
0.35f, 0.6f,
0.2f, 0.6f,
0.35f, -0.6f,
0.2f, 0.6f,
0.2f, -0.6f,
// middle bar
-0.2f, -0.1f,
-0.2f, 0.1f,
0.2f, 0.1f,
-0.2f, -0.1f,
0.2f, 0.1f,
0.2f, -0.1f,
// bottom bar
-0.35f, -0.7f,
-0.35f, -0.9f,
0.35f, -0.9f,
-0.35f, -0.7f,
0.35f, -0.9f,
0.35f, -0.7f
};
GLfloat colors[] = {
// R // G // B
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.3f,
1.0f, 0.3f, 0.0f,
1.0f, 0.3f, 0.3f,
1.0f, 0.3f, 0.6f,
1.0f, 0.6f, 0.3f,
0.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.3f,
0.3f, 1.0f, 0.0f,
0.3f, 1.0f, 0.3f,
0.3f, 1.0f, 0.6f,
0.6f, 1.0f, 0.3f,
0.3f, 0.3f, 1.0f,
0.3f, 0.6f, 1.0f,
0.6f, 0.3f, 1.0f,
0.3f, 0.3f, 1.0f,
0.3f, 0.6f, 1.0f,
0.6f, 0.3f, 1.0f,
1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.1f,
1.0f, 1.0f, 0.2f,
1.0f, 1.0f, 0.7f,
1.0f, 1.0f, 0.8f,
1.0f, 1.0f, 0.9f
};
DEBUG("Creating vertext buffer"); DEBUG("Creating vertext buffer");
GLuint vertexBuffer; GLuint vertexBuffer;
@ -213,13 +127,6 @@ void init(void) {
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
DEBUG("Creating colour buffer");
GLuint colorBuffer;
glGenBuffers(1, &colorBuffer);
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
DEBUG("Creating vertex array object"); DEBUG("Creating vertex array object");
// create vertex array object // create vertex array object
glGenVertexArrays(1, &vertexArrayObject); glGenVertexArrays(1, &vertexArrayObject);
@ -237,12 +144,6 @@ void init(void) {
); );
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
// vertex color data
glBindBuffer(GL_ARRAY_BUFFER, colorBuffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0); glBindVertexArray(0);
@ -269,7 +170,7 @@ void draw(void) {
glUniform2f(positionLocation, cos(currentHue * 2 * M_PI) * 0.2f, sin(currentHue * 2 * M_PI) * 0.2f); glUniform2f(positionLocation, cos(currentHue * 2 * M_PI) * 0.2f, sin(currentHue * 2 * M_PI) * 0.2f);
glBindVertexArray(vertexArrayObject); glBindVertexArray(vertexArrayObject);
glDrawArrays(GL_TRIANGLES, 0, 48); glDrawArrays(GL_TRIANGLE_STRIP, 0, (resolution + 1) * 2);
} }
void framebuffer_size_callback(GLFWwindow* window, int width, int height) { void framebuffer_size_callback(GLFWwindow* window, int width, int height) {

View File

@ -1,11 +1,9 @@
#version 330 core #version 330 core
layout (location = 0) in vec2 aPosition; layout (location = 0) in vec2 aPosition;
layout (location = 1) in vec3 aColor;
uniform vec2 uPosition;
out vec3 vertexColor; out vec3 vertexColor;
void main() { void main() {
vertexColor = aColor; vertexColor = vec3(1.0, 0.0, 0.0);
gl_Position = vec4(uPosition + aPosition, 0.0, 1.0); gl_Position = vec4(aPosition, 0.0, 1.0);
} }