Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Template1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <Windows.h>
- #include "include\GL\GL.H"
- #include "include\GL\GLU.H"
- #include "include\GL\glut.h"
- #include <stdbool.h>
- // CONFIGURATION
- bool rotateAroundWindowCentre = true;
- bool rotateAroundMassCentre = true;
- bool changeDistanceFromWindowCentre = false;
- // CONFIGURATION
- GLfloat rotation = 0;
- GLfloat rotationMassCentre = 0;
- void redisplay(int time) {
- glutPostRedisplay();
- }
- void DrawTriangle(void) {
- //glRotatef(rotation * 0.01f, .0f, .0f, 1.0f);
- glBegin(GL_POLYGON);// OpenGL’a state
- glColor4f(1.0f, 0.0f, 0.0f, 1.0f);//Red;
- glVertex2f(0.0f, 0.0f);
- glColor4f(0.0f, 1.0f, 0.0f, 1.0f);//Green
- glVertex2f(60.0f, 0.0f);
- glColor4f(0.0f, 0.0f, 1.0f, 1.0f);//Blue
- glVertex2f(0.0f, 60.0f);
- glEnd();
- }
- void resetMatrix() {
- glPopMatrix();
- glPushMatrix();
- }
- void rotateCentre() {
- if (rotateAroundMassCentre) {
- glTranslatef(20.0f, 20.0f, 0.0f);
- glRotatef(rotationMassCentre, 0.0f, 0.0f, 1.0f);
- glTranslatef(-20.0f, -20.0f, 0.0f);
- }
- }
- void drawFirstSeriesOfTriangles() {
- glPushMatrix();
- for (int i = 0; i < 4; ++i) {
- glPushMatrix();
- rotateCentre();
- DrawTriangle();
- glPopMatrix();
- glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
- }
- glPopMatrix();
- }
- void drawSecondSeriesOfTriangles() {
- glPushMatrix();
- for (int i = 0; i < 4; ++i) {
- glRotatef((i) * 90.0f, 0.0f, 0.0f, 1.0f);
- // left side triangle
- glPushMatrix();
- glTranslatef(100.0f, 0.0f, 0.0f);
- rotateCentre();
- DrawTriangle();
- // right side triangle
- glPopMatrix();
- glTranslatef(0.0f, 100.0f, 0.0f);
- rotateCentre();
- DrawTriangle();
- resetMatrix();
- }
- glPopMatrix();
- }
- void drawThirdSeriesOfTriangles() {
- glPushMatrix();
- for (int i = 0; i < 4; ++i) {
- glRotatef((i) * 90.0f, 0.0f, 0.0f, 1.0f);
- // right triangle
- glTranslatef(200.0f, 0.0f, 0.0f);
- glPushMatrix();
- rotateCentre();
- DrawTriangle();
- glPopMatrix();
- // middle triangle
- glTranslatef(-100.0f, 100.0f, 0.0f);
- glPushMatrix();
- rotateCentre();
- DrawTriangle();
- glPopMatrix();
- // left triangle
- glTranslatef(-100.0f, 100.0f, 0.0f);
- glPushMatrix();
- rotateCentre();
- DrawTriangle();
- glPopMatrix();
- resetMatrix();
- }
- glPopMatrix();
- }
- void MyDisplay(void) {
- glLoadIdentity(); // does not work with it
- // The new scene
- glClear(GL_COLOR_BUFFER_BIT);
- glPushMatrix();
- if (rotateAroundWindowCentre)
- glRotatef(rotation * 0.01f, 0.0f, 0.0f, 1.0f);
- drawFirstSeriesOfTriangles();
- drawSecondSeriesOfTriangles();
- drawThirdSeriesOfTriangles();
- glPopMatrix();
- // The end of scene
- glFlush();//start processing buffered OpenGL routines
- ++rotation;
- rotationMassCentre += 0.03;
- // call MyDisplay function
- glutPostRedisplay();
- //glutTimerFunc(1000, redisplay, 0);
- }
- void MyInit(void) {
- glClearColor(0.0, 0.0, 0.0, 0.0); //select clearing (background) color
- /* initialize viewing values */
- glViewport(0, 0, 300, 300); //window origin and size
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();//=1
- gluOrtho2D(-350.0, 350.0, -350.0, 350.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();//=1
- }
- int main(int argc, char** argv) { //<- for normal API
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);//single buffer and RGBA
- glutInitWindowSize(500, 500);//initial window size
- glutInitWindowPosition(100, 100);
- glutCreateWindow("My window");//create widnow, hello title bar
- MyInit();
- glutDisplayFunc(MyDisplay);//
- glutMainLoop();//enter main loop and process events
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement