57 lines
1.4 KiB
C++
57 lines
1.4 KiB
C++
#include<glad/glad.h>
|
|
#include<GLFW/glfw3.h>
|
|
#include <chrono>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <thread>
|
|
|
|
void render(){
|
|
glBegin(GL_POINTS);
|
|
glVertex3f(0.0f,0.5f,0.0f);
|
|
glVertex3f(-0.5,-0.5,0.0f);
|
|
glVertex3f(0.5f,-0.5f,0.0f);
|
|
glEnd();
|
|
}
|
|
|
|
int main(){
|
|
// 初始化GLFW
|
|
if(glfwInit()==0){
|
|
throw std::runtime_error("failed to init GLFW");
|
|
}
|
|
GLFWwindow *window = glfwCreateWindow(640,480,"Example",nullptr,nullptr);
|
|
|
|
if(window==nullptr){
|
|
glfwTerminate();
|
|
throw std::runtime_error("GLFW failed to create window");
|
|
}
|
|
|
|
glfwMakeContextCurrent(window);//创建上下文
|
|
|
|
if(gladLoadGL()==0){ //加载GL函数
|
|
glfwTerminate();
|
|
throw std::runtime_error("GLAD Load GL functions failed");
|
|
}
|
|
|
|
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(64.0f);
|
|
|
|
while(glfwWindowShouldClose(window)==false){
|
|
render();
|
|
glfwSwapBuffers(window);
|
|
glfwPollEvents();
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000/60));
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#ifdef _MSC_VER
|
|
#include<Windows.h>
|
|
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
|
main();
|
|
}
|
|
#endif |