最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

OpenGL 渲染三角形示例[不要看注釋...]

2023-06-12 15:02 作者:上官清逸_馨逸  | 我要投稿

#define GLEW_STATIC


#include <iostream>


#include <GL/glew.h>

#include <GLFW/glfw3.h>




void EscInput(GLFWwindow *win);


float vertices[]={

-0.5f,-0.5f,0.0f,

0.5f,-0.5f,0.0f,

0.0f, 0.5f,0.0f

};


const char *vertexShaderSource =

"#version 330 core\n"

"layout (location = 0) in vec3 aPos;\n"

"void main()\n"

"{\n"

" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"

"}\n";


const char *fragmentShaderSource=

"#version 330 core\n"

"out vec4 FragColor;\n"

"void main()\n"

"{\n"

" FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"

"}\n";




int main(){


glfwInit(); //初始化

glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR,3);//提示1:用主版本

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR,3);//提示2:用子版本

glfwWindowHint(GLFW_OPENGL_PROFILE,GLFW_OPENGL_CORE_PROFILE);//提示3:使用啥

/*glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT,GL_TRUE);*/ //提示4:使用mac兼容


//new一個(gè) GLFWwindow 對(duì)象 并設(shè)置w,h,"title_text",null,null

GLFWwindow *win = glfwCreateWindow(800,600,"Test window",NULL,NULL);


if(win == NULL){

std::cout<<"Open Window Failed\n";

glfwTerminate();

return -1;//失敗則結(jié)束

}

glfwMakeContextCurrent(win);


//=============================

glewExperimental = true;//bool


if(glewInit()!= GLEW_OK){

std::cout<<"glew init failed\n";

glfwTerminate();

return -1;

}


glViewport(0,0,800,600);//設(shè)置窗口維度(屏幕x,屏幕y,窗口x,窗口y)貌似沒(méi)鳥(niǎo)用




unsigned int VAO;

glGenVertexArrays(1,&VAO);

glBindVertexArray(VAO);


unsigned int VBO;

glGenBuffers(1,&VBO);

glBindBuffer(GL_ARRAY_BUFFER,VBO);

glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW);


unsigned int vertexShader;

vertexShader = glCreateShader(GL_VERTEX_SHADER);

glShaderSource(vertexShader,1,&vertexShaderSource,NULL);

glCompileShader(vertexShader);


unsigned int fragmentShader;

fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);

glShaderSource(fragmentShader,1,&fragmentShaderSource,NULL);

glCompileShader(fragmentShader);


unsigned int shaderProgram;

shaderProgram = glCreateProgram();

glAttachShader(shaderProgram,vertexShader);

glAttachShader(shaderProgram,fragmentShader);

glLinkProgram(shaderProgram);


glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,3*sizeof(float),(void*)0);

glEnableVertexAttribArray(0);








while(!glfwWindowShouldClose(win)){ //循環(huán)渲染 (每幀[30/60/120])

glClearColor(0.1137254901960784,0.85,1,1.0); //設(shè)置顏色

glClear(GL_COLOR_BUFFER_BIT);




//自定義函數(shù)

EscInput(win);




//繪制三角形

glBindVertexArray(VAO);

glUseProgram(shaderProgram);

glDrawArrays(GL_TRIANGLES,0,3);





glfwSwapBuffers(win); //顏色繪制與輸出2D屏幕

glfwPollEvents();

}


glfwTerminate(); //釋放/刪除之前的資源

return 0;

}


//當(dāng)按下ESC時(shí),退出

void EscInput(GLFWwindow *win){

if(glfwGetKey(win,GLFW_KEY_ESCAPE)==GLFW_PRESS){

std::cout<<"eixt!\n";

glfwSetWindowShouldClose(win,1);

}

}


OpenGL 渲染三角形示例[不要看注釋...]的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
宁晋县| 应用必备| 文山县| 丹棱县| 广西| 台南县| 哈巴河县| 边坝县| 峨眉山市| 南和县| 青河县| 谢通门县| 乃东县| 缙云县| 舒兰市| 台州市| 宁城县| 准格尔旗| 济阳县| 宿州市| 大同县| 商都县| 秦皇岛市| 综艺| 清原| 内乡县| 平舆县| 安远县| 邮箱| 崇礼县| 横山县| 新津县| 叙永县| 济南市| 察雅县| 合山市| 鄂托克前旗| 彰武县| 井冈山市| 台中市| 岳西县|