配置
GLUT配置
https://www.cnblogs.com/flylinmu/p/7823019.html
GLEW配置
https://blog.csdn.net/qq_41843732/article/details/84574176
GLFW以及GLAD配置
https://learnopengl-cn.github.io/01%20Getting%20started/02%20Creating%20a%20window/
头文件格式
#include<stdio.h>
// include glut & glew
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
int main() {
return 0;
}
画点
#include<stdio.h>
#include<GL/glut.h>
#include <GLFW/glfw3.h>
#include <iostream>
using namespace std;
void framebuffer_size_callback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
}
void processInput(GLFWwindow* window) {
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
glfwSetWindowShouldClose(window, true);
}
}
void ffff() {
GLfloat sizesPoint[2];//保存线宽的尺寸范围
GLfloat stepPoint;//保存线宽度尺寸的最小间隔
GLfloat curSizePoint;
glGetFloatv(GL_POINT_SIZE_RANGE, sizesPoint);
glGetFloatv(GL_POINT_SIZE_GRANULARITY, &stepPoint);
curSizePoint = sizesPoint[0];
for (int i = 0; i < 25; i++) {
glPointSize(curSizePoint);
glBegin(GL_POINTS);
glVertex3f(25.0 + i * 8, 200.0f, 0.0f);
glEnd();
curSizePoint += stepPoint * 2;
}
}
void drawPoint()
{
/* Draw a point */
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glPointSize(2.0f);
glBegin(GL_POINTS);
glColor3f(1.0, 0.0, 0.0); // Red
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, 0.8f);
glEnd();
}
void drawLint()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(2);//设置线段宽度
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 0.0);
glVertex2f(0.8, 1); //定点坐标范围
glVertex2f(0, -1);
glEnd();
}
void drawTriangle()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0); // Red
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0); // Green
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 0.0, 1.0); // Blue
glVertex3f(1.0, -1.0, 0.0);
glEnd();
}
int main() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(600,800,"OPENGL",NULL,NULL);
while (!glfwWindowShouldClose(window)) {
processInput(window);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
drawTriangle();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}