lxxzq / win

0 stars 0 forks source link

ddd #1

Open lxxzq opened 5 years ago

lxxzq commented 5 years ago

include "stdafx.h"

if GL6

include

include

include <GL/glew.h>

include <GL/glut.h>

include "libmath.h"

vec2 vertices[4] = { { -0.6f, -0.6f }, { 0.6f, -0.6f }, { 0.6f, 0.6f }, { -0.6f, 0.6f } }; char vertex_shader_text = "#version 110\n" "uniform mat4 MVP;\n" "attribute vec2 vPos;\n" "void main()\n" "{\n" " gl_Position = MVP vec4(vPos, 0.0, 1.0);\n" "}\n"; char* fragment_shader_text = "#version 110\n" "void main()\n" "{\n" " gl_FragColor = vec4(1.0);\n" "}\n";

GLuint vertex_buffer, vertex_shader; GLuint fragment_shader, program; GLint mvp_location, vpos_location; int width, height; float ratio; mat4x4 m, p, mvp;

define M_PI 3.1415926

double angle = 234 * M_PI / 180.0;

void display(void) { SYSTEMTIME sys; GetLocalTime(&sys); int a = sys.wHour 3600 + sys.wMinute 60 + sys.wSecond; angle = a * M_PI / 180.0;

glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(program);

mat4x4_ortho(p, -ratio, ratio, -1.f, 1.f, 0.f, 1.f);

mat4x4_translate(m, -1.f, 0.f, 0.f);
mat4x4_rotate_Z(m, m, (float)angle);
mat4x4_mul(mvp, p, m);

glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*)mvp);
glDisable(GL_MULTISAMPLE);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

mat4x4_translate(m, 1.f, 0.f, 0.f);
mat4x4_rotate_Z(m, m, (float)angle);
mat4x4_mul(mvp, p, m);

glUniformMatrix4fv(mvp_location, 1, GL_FALSE, (const GLfloat*)mvp);
glEnable(GL_MULTISAMPLE);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);

glFlush();
glutSwapBuffers();

} void idle(void) { display(); ::Sleep(1); } void reshape(int w, int h) { width = w; height = h; ratio = (float)w / (float)h; glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity();

} void GL_ERROR() { GLenum e = glGetError(); if (e > 0) printf("%s\n", glewGetErrorString(e)); }

void init(void) { //glEnable(GL_DEPTH_TEST); glGenBuffers(1, &vertex_buffer); glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); vertex_shader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertex_shader, 1, &vertex_shader_text, 0); glCompileShader(vertex_shader); GL_ERROR(); fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fragment_shader, 1, &fragment_shader_text, 0); glCompileShader(fragment_shader); GL_ERROR(); program = glCreateProgram(); glAttachShader(program, vertex_shader); glAttachShader(program, fragment_shader); glLinkProgram(program); GL_ERROR(); mvp_location = glGetUniformLocation(program, "MVP"); vpos_location = glGetAttribLocation(program, "vPos"); glEnableVertexAttribArray(vpos_location); glVertexAttribPointer(vpos_location, 2, GL_FLOAT, GL_FALSE, sizeof(vertices[0]), (void*)0); GL_ERROR();

int samples;
glGetIntegerv(GL_SAMPLES, &samples);
if (samples)
    printf("Context reports MSAA is available with %i samples\n", samples);
else
    printf("Context reports MSAA is unavailable\n");

} int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_MULTISAMPLE); glutInitWindowPosition(0, 0); glutInitWindowSize(500, 500); glutCreateWindow("Demo");

if (glewInit() != GLEW_OK)
{
    printf("glewInit error\n");
    system("pause");
    return 0;
}
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();

return 0;

}

endif

lxxzq commented 5 years ago
angle += 0.01f;
if (angle >= 360.0f)
    angle = 0.0f;