OpenGL 基础

配置

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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值