Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
|
7b28b5621f |
125
src/main.c
125
src/main.c
|
@ -22,6 +22,8 @@ GLuint initialWindowHeight = 600;
|
|||
int frameCount = 0;
|
||||
struct timespec last_time, current_time;
|
||||
|
||||
unsigned int resolution = 50;
|
||||
|
||||
typedef struct ColorRGB {
|
||||
GLfloat r;
|
||||
GLfloat g;
|
||||
|
@ -106,105 +108,17 @@ void init(void) {
|
|||
|
||||
INFO("Shader Program Done.");
|
||||
|
||||
// create triangle buffer
|
||||
/**
|
||||
* -0.35 0.35
|
||||
* | -0.2 0.2 |
|
||||
* | | | |
|
||||
*
|
||||
* +----+ +----+ --- 0.6
|
||||
* | | | |
|
||||
* | | | |
|
||||
* | +--------+ | --- 0.1
|
||||
* | |
|
||||
* | +--------+ | --- -0.1
|
||||
* | | | |
|
||||
* | | | |
|
||||
* +----+ +----+ --- -0.6
|
||||
*
|
||||
* +------------------+ --- -0.7
|
||||
* | |
|
||||
* +------------------+ --- -0.9
|
||||
*
|
||||
*/
|
||||
GLfloat innerRadius = 0.2f;
|
||||
GLfloat outerRadius = 0.8f;
|
||||
|
||||
GLfloat vertices[] = {
|
||||
// X // Y
|
||||
|
||||
// left 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,
|
||||
|
||||
// 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
|
||||
};
|
||||
GLfloat vertices[(resolution + 1) * 2 * 2];
|
||||
for (unsigned int i = 0; i <= resolution; i++) {
|
||||
GLfloat angle = ((float)i) / resolution * 2 * M_PI;
|
||||
vertices[4 * i + 0] = innerRadius * cos(angle);
|
||||
vertices[4 * i + 1] = innerRadius * sin(angle);
|
||||
vertices[4 * i + 2] = outerRadius * cos(angle);
|
||||
vertices[4 * i + 3] = outerRadius * sin(angle);
|
||||
}
|
||||
|
||||
DEBUG("Creating vertext buffer");
|
||||
GLuint vertexBuffer;
|
||||
|
@ -213,13 +127,6 @@ void init(void) {
|
|||
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||||
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");
|
||||
// create vertex array object
|
||||
glGenVertexArrays(1, &vertexArrayObject);
|
||||
|
@ -237,12 +144,6 @@ void init(void) {
|
|||
);
|
||||
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);
|
||||
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);
|
||||
|
||||
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) {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
#version 330 core
|
||||
layout (location = 0) in vec2 aPosition;
|
||||
layout (location = 1) in vec3 aColor;
|
||||
uniform vec2 uPosition;
|
||||
|
||||
out vec3 vertexColor;
|
||||
|
||||
void main() {
|
||||
vertexColor = aColor;
|
||||
gl_Position = vec4(uPosition + aPosition, 0.0, 1.0);
|
||||
vertexColor = vec3(1.0, 0.0, 0.0);
|
||||
gl_Position = vec4(aPosition, 0.0, 1.0);
|
||||
}
|
Loading…
Reference in New Issue