opengl_x11

Playing with OpenGL
git clone git://bsandro.tech/opengl_x11
Log | Files | Refs

commit ddaa91f5b7a296c327964ab85854b49e3114065f
parent 72fdb4b86782b4b3d47328cc2905f7782a738a9c
Author: bsandro <email@bsandro.tech>
Date:   Thu, 16 Oct 2025 00:48:10 +0300

2 triangles and a square changing colors

Diffstat:
Mmain1.c | 26+++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/main1.c b/main1.c @@ -46,9 +46,9 @@ uniform double iTime; \n\ in vec3 color; \n\ out vec4 outColor; \n\ void main() { \n\ - float c = abs(sin(float(iTime))); \n\ -// outColor = vec4(c, 0.5, 0.3, 1.0); \n\ - outColor = vec4(color, 1.0); \n\ + float c1 = abs(sin(float(iTime))); \n\ + float c2 = abs(cos(float(iTime))); \n\ + outColor = vec4(color+c1-c2, 1.0); \n\ } \n\ "; @@ -119,17 +119,24 @@ int main(int argc, char *argv[]) { // [x, y, r, g, b] static const GLfloat vertices[] = { 0.01f, 0.01f, 1.0f, 0.0f, 0.0f, - 0.4f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.4f, 0.0f, 0.0f, 1.0f, + 0.8f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.8f, 0.0f, 0.0f, 1.0f, -0.01f, -0.01f, 0.0f, 0.0f, 1.0f, - -0.4f, 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, -0.4f, 1.0f, 0.0f, 0.0f + -0.8f, 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, -0.8f, 1.0f, 0.0f, 0.0f, + + 0.3f, 0.3f, 1.0f, 0.0f, 0.0f, + 0.3f, 0.6f, 1.0f, 0.0f, 0.0f, + 0.6f, 0.3f, 1.0f, 0.0f, 0.0f, + 0.6f, 0.6f, 1.0f, 0.0f, 0.0f }; static const GLuint elements[] = { 0, 1, 5, - 3, 2, 4 + 3, 2, 4, + 6, 7, 8, + 7, 8, 9 }; GLuint vbo; @@ -183,10 +190,7 @@ int main(int argc, char *argv[]) { GLint color = glGetAttribLocation(shaderPrg, "inColor"); glEnableVertexAttribArray(color); glVertexAttribPointer(color, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), (void *)(2*sizeof(GLfloat))); - //glDrawArrays(GL_TRIANGLES, 0, sizeof(vertices)/sizeof(GLfloat)/5); glDrawElements(GL_TRIANGLES, sizeof(elements), GL_UNSIGNED_INT, 0); - //glDisableVertexAttribArray(0); - //glUseProgram(0); glXSwapBuffers(dpy, win); usleep(1000*16);