OpenGL-JIN/example/displayers.cpp

103 lines
1.9 KiB
C++
Raw Normal View History

2019-09-24 11:34:40 +02:00
//
// Created by trotfunky on 24/09/2019.
//
#include "displayers.h"
void display_pyramid(float x, float y, float z, float c, float h)
{
glBegin(GL_TRIANGLES);
// First side
glColor3f(1,0,0);
// Summit
glVertex3f(x,y+h,z);
glVertex3f(x+c/2,y,z+c/2);
glVertex3f(x-c/2,y,z+c/2);
// Second side
glColor3f(0,1,0);
glVertex3f(x,y+h,z);
glVertex3f(x+c/2,y,z+c/2);
glVertex3f(x+c/2,y,z-c/2);
// Third side
glColor3f(0,0,1);
glVertex3f(x,y+h,z);
glVertex3f(x-c/2,y,z+c/2);
glVertex3f(x-c/2,y,z-c/2);
// Fourth side
glColor3f(1,1,0);
glVertex3f(x,y+h,z);
glVertex3f(x-c/2,y,z-c/2);
glVertex3f(x+c/2,y,z-c/2);
glEnd();
// Bottom
glBegin(GL_QUADS);
glColor3f(0,1,1);
glVertex3f(x-c/2,y,z-c/2);
glVertex3f(x-c/2,y,z+c/2);
glVertex3f(x+c/2,y,z+c/2);
glVertex3f(x+c/2,y,z-c/2);
glEnd();
}
void display_rotating_pyramid(float x, float y, float z, float c, float h, float alpha)
{
glPushMatrix();
glTranslatef(x,0,z);
glRotatef(alpha,0,1,0);
glTranslatef(-x,0,-z);
display_pyramid(x,y,z,c,h);
glPopMatrix();
}
2019-09-25 00:36:57 +02:00
void display_tree(float x, float y, float z, float h, float w, const Texture& tree_texture)
2019-09-24 11:34:40 +02:00
{
glEnable(GL_ALPHA_TEST);
2019-09-25 00:36:57 +02:00
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glBindTexture(GL_TEXTURE_2D,tree_texture.opengl_id[0]);
glColor4f(1.0f, 1.0f, 1.0f,1.00);
2019-09-24 11:34:40 +02:00
glBegin(GL_QUADS);
2019-09-25 00:36:57 +02:00
// First rectangle
glTexCoord2f(1,0);
2019-09-24 11:34:40 +02:00
glVertex3f(x+w/2,y,z);
2019-09-25 00:36:57 +02:00
glTexCoord2f(0,0);
2019-09-24 11:34:40 +02:00
glVertex3f(x-w/2,y,z);
2019-09-25 00:36:57 +02:00
glTexCoord2f(0,1);
2019-09-24 11:34:40 +02:00
glVertex3f(x-w/2,y+h,z);
2019-09-25 00:36:57 +02:00
glTexCoord2f(1,1);
2019-09-24 11:34:40 +02:00
glVertex3f(x+w/2,y+h,z);
2019-09-25 00:36:57 +02:00
// Second rectangle
glTexCoord2f(1,0);
2019-09-24 11:34:40 +02:00
glVertex3f(x,y,z+w/2);
2019-09-25 00:36:57 +02:00
glTexCoord2f(0,0);
2019-09-24 11:34:40 +02:00
glVertex3f(x,y,z-w/2);
2019-09-25 00:36:57 +02:00
glTexCoord2f(0,1);
2019-09-24 11:34:40 +02:00
glVertex3f(x,y+h,z-w/2);
2019-09-25 00:36:57 +02:00
glTexCoord2f(1,1);
2019-09-24 11:34:40 +02:00
glVertex3f(x,y+h,z+w/2);
2019-09-25 00:36:57 +02:00
2019-09-24 11:34:40 +02:00
glEnd();
glDisable(GL_ALPHA_TEST);
2019-09-24 11:34:40 +02:00
}