Такой себе мини бенчмарк хотелось сделать на OpenGL.
Код
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <cstdlib>
#include <windows.h>
#include <math.h>
double size = 5;
const int X = 250, Y = 250;
GLfloat light_position[]={0.0,2.0,0.0,0.0};
GLfloat light_global[]={1,1,1,1};
GLfloat white_light[]={1,1,1,1};
GLfloat mat_color[]={1,1,1,1};
GLfloat mat_specular[]={0.7,0.7,0.7,1};
GLfloat mat_shininess[]={60.0};
double angle = 0,angle_global = 0;
class Checker{
private:
double x,y,z;
public:
void Draw(){
glPushMatrix();
glTranslatef(x,y,z);
glRotatef(-90,1,0,0);
glutSolidCone(3,5,10,10);
glPopMatrix();
}
void Set(double x, double y, double z){
Checker::x = x; Checker::y = y; Checker::y = y;
}
};
void draw_game_board(){
glPushMatrix();
glScalef(1,2,1);
glTranslatef(-size*(X-1)/2,0,size*Y/2);
for( int y = 0; y < Y; y++ ){
angle = 0 + angle_global;
for(int x = 0; x < X; x++ ){
mat_specular[0] *= -1;
mat_specular[1] *= -1;
mat_specular[2] *= -1;
glPushMatrix();
glTranslatef(0,sin(angle)*20,0);
angle += 0.15;
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_specular);
glutSolidCube(size);
glPopMatrix();
glTranslatef(size,0,0);
}
mat_specular[0] *= -1;
mat_specular[1] *= -1;
mat_specular[2] *= -1;
glTranslatef(-size*X,0,-size);
}
glPopMatrix();
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
draw_game_board();
glPushMatrix();
glPopMatrix();
glutSwapBuffers();
glutPostRedisplay();
angle_global += 0.05;
}
void Init(){
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,light_global);
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
glLightfv(GL_LIGHT0,GL_DIFFUSE,white_light);
glLightfv(GL_LIGHT0,GL_SPECULAR,white_light);
glClearDepth(1);
glClearColor(0.3,1,0.5,0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 0.1f, 1000.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(500, 500, 500, 0, 0, 0, 0, 1, 0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_color);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
}
int main(int argc, char** argv){
srand(4541);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutInitWindowPosition(80, 80);
glutInitWindowSize(1024, 800);
glViewport(0,0,1024,800);
glutCreateWindow("Learn OpenGL");
glutDisplayFunc(display);
Init();
glutMainLoop();
}