This commit is contained in:
Zengtudor 2024-09-01 20:35:10 +08:00
parent 47f81f37a7
commit ee649c5a21
1 changed files with 16 additions and 8 deletions

View File

@ -1,23 +1,25 @@
#include <cmath>
#include <cstdlib>
#include <format>
#include<glad/glad.h>
#include<GLFW/glfw3.h>
#include <chrono>
#include <iostream>
#include <ostream>
#include <stdexcept>
#include <thread>
const float POINT_SIZE = 32.0f;
void render(){
glBegin(GL_TRIANGLES);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,0.5f,0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-0.5,-0.5,0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(0.5f,-0.5f,0.0f);
glEnd();
glBegin(GL_POINTS);
@ -31,10 +33,16 @@ void render(){
num=0.0f;
speed=0.01f;
}
glColor3f(num,num,num);
glVertex3f(0.0f,0.0f,0.0f);
glColor3f(num/1.11f,1.0f-(num/1.12f),num/1.13f);
static int bx=0,by=0,bsx=5,bsy=7;
glVertex3f(float(bx)/1000.0f,float(by)/1000.0f,0.0f);
bx+=bsx,by+=bsy;
if(bx>=1000||bx<=-1000){
bsx=-bsx;
}
if(by>=1000||by<=-1000){
bsy=-bsy;
}
glEnd();
}
@ -59,17 +67,17 @@ int main(){
std::cout<<"OpenGL version:"<<glGetString(GL_VERSION)<<"\n";
glClear(GL_COLOR_BUFFER_BIT);
glEnable(GL_POINT_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glPointSize(POINT_SIZE);
while(glfwWindowShouldClose(window)==false){
glClear(GL_COLOR_BUFFER_BIT);
render();
glfwSwapBuffers(window);
glfwPollEvents();
std::this_thread::sleep_for(std::chrono::milliseconds(1000/60));
std::this_thread::sleep_for(std::chrono::milliseconds(1000/120));
}
return 0;
}