当前位置:网站首页>Compile oglpg-9th-edition source code with clion
Compile oglpg-9th-edition source code with clion
2022-07-02 19:06:00 【A Sheng】
OpenGL It is a software library that can access the characteristics of graphics hardware devices , its 1.0 Version released at 1994 year 7 month , Mainly used in computer graphics . With AR and VR The development of , Computer graphics algorithms will become increasingly important , Like ray tracing [RayTracing].
One . Compile source code
Use CLion open OGLPG-9th-Edition Source code [1], Create in the root directory build Folder , then cd build, Carry out orders cmake .., The error is reported as follows :
The solution is to comment CMakeLists.txt In the document 92-94 Line code : 
Two . Have a problem
Unable to open file encountered glfw3_d.lib The question is , Need to compile OGLPG-9th-Edition\lib\glfw Source code [3]:
Compiling solutions , stay OGLPG-9th-Edition\lib\glfw\build\src\Debug Can be found in glfw3.lib and glfw3.pdb file :
take glfw3.lib and glfw3.pdb Rename it to glfw3_d.lib and glfw3_d.pdb after , copy to OGLPG-9th-Edition\lib Below directory : 
3、 ... and . Running example
Running example 01-keypress.cpp As shown below :
Running example 01-triangles.cpp As shown below : 
Four .01-triangles.cpp Source code analysis
(1) Vertex shaders and fragment shaders
GLFW What is the library ?GLFW It's used to create OpenGL Context and a third-party library of operation windows . that Glew What is a library ? Due to the OpenGL Of API There are differences ,Glew[OpenGL Extension Wrangler Library] Just put these API An integrated library . Vertex Shader ( Including subdivision and geometric coloring ) Determines where an element should be on the screen , Slice coloring uses this information to determine what the color of a slice should be .
(2)OpenGL and C Data type correspondence
| suffix | data type | C Language data type | Corresponding OpenGL type |
|---|---|---|---|
| b | 8 An integer | signed char | GLbyte |
| s | 16 An integer | signed short | GLshort |
| i | 32 An integer | int | GLint、GLsizei |
| f | 32 Bit floating point type | float | GLfloat、GLclampf |
| d | 64 Bit floating point type | double | GLdouble、GLclampd |
| ub | 8 Bit unsigned integer | unsigned char | GLubyte |
| us | 16 Bit unsigned integer | unsigned short | GLushort |
| ui | 32 Bit unsigned integer | unsigned int | GLuint、GLenum、GLbitfield |
(3)01-triangles.cpp File source code and comments
#include "vgl.h"
#include "LoadShaders.h"
enum VAO_IDs { Triangles, NumVAOs };
enum Buffer_IDs { ArrayBuffer, NumBuffers };
enum Attrib_IDs { vPosition = 0 };
GLuint VAOs[NumVAOs];
GLuint Buffers[NumBuffers];
const GLuint NumVertices = 6;
void init( void )
{
// n: Specify the number of vertex array object names to generate
// arrays: Specifies the array to store the name of the generated vertex array object
// Assign vertex array objects : return n Unused object names to array arrays in , Used as a vertex array object
glGenVertexArrays( NumVAOs, VAOs );
// array: Specify the name of the bound vertex array
// Create and bind a vertex array object
glBindVertexArray( VAOs[Triangles] );
GLfloat vertices[NumVertices][2] = {
{ -0.90f, -0.90f }, { 0.85f, -0.90f }, { -0.90f, 0.85f }, // Triangle 1
{ 0.90f, -0.85f }, { 0.90f, 0.90f }, { -0.85f, 0.90f } // Triangle 2
};
// void glCreateBuffers(GLsizei n, GLuint* buffers);
// return n Currently unused cache object names ( Each represents a newly created cache object ), And save to buffers Array
glCreateBuffers( NumBuffers, Buffers );
// void glBindBuffer(GLenum target, GLuint buffer);
// Name as buffer The cache object of is bound to target The specified cache join point .target Must be OpenGL One of the supported cache binding targets ,buffer It has to be through glCreateBuffers() The name of the assignment .
// If buffer It is the first time to be bound , Then the corresponding cache object will also be created .
glBindBuffer( GL_ARRAY_BUFFER, Buffers[ArrayBuffer] );
// void glBufferStorage(GLenum target, GLsizeiptr size, const void * data, GLbitfield flags);
// glBufferStorage Create a new immutable data store for the object currently bound to the target buffer
glBufferStorage( GL_ARRAY_BUFFER, sizeof(vertices), vertices, 0);
ShaderInfo shaders[] =
{
{ GL_VERTEX_SHADER, "media/shaders/triangles/triangles.vert" },
{ GL_FRAGMENT_SHADER, "media/shaders/triangles/triangles.frag" },
{ GL_NONE, NULL }
};
GLuint program = LoadShaders( shaders );
glUseProgram( program );
// glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer);
// index: Attribute positions in shaders
// size: Indicates the number of components that need to be updated for each vertex , It can be 1、2、3、4 or GL_BGRA
// type: Specify the data type of each element in the array
// normalized: Set whether the vertex data needs to be normalized before storage
// stride: The size offset value between every two elements in the array
// pointer: Indicates in the cache object , The offset value of the array data calculated from the starting position , Use basic system units byte
glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) );
glEnableVertexAttribArray( vPosition );
}
void display( void )
{
static const float black[] = { 0.0f, 0.0f, 0.0f, 0.0f };
// Clear the data in the frame cache before rendering
// GL_COLOR: Cache type cleared
// 0: Set the cache index to be cleared
// back: Set the color after clearing the cache
glClearBufferfv(GL_COLOR, 0, black);
// Select the vertex array to use as vertex data
glBindVertexArray( VAOs[Triangles] );
// Request rendering geometry
glDrawArrays( GL_TRIANGLES, 0, NumVertices );
}
int main( int argc, char** argv )
{
// glfw Initialization and configuration
glfwInit();
// At the same time, create a new rendering window OpenGL Environmental Science , Used to execute rendering instructions
GLFWwindow* window = glfwCreateWindow(800, 600, "Triangles", NULL, NULL);
// Set up window Associated with the window in OpenGL The environment is the current environment
glfwMakeContextCurrent(window);
// initialization GL3W library , establish OpenGL Before environment , This direction must be called once
gl3wInit();
// Set the data used in the program
init();
while (!glfwWindowShouldClose(window))
{
// Rendering work
display();
// Swap the front-end and back-end caches of the window , Go back to the content and show it
glfwSwapBuffers(window);
// Handle all waiting events , Check any information returned by the operating system
glfwPollEvents();
}
// Destroy the specified window and its context , Determine whether the window needs to be closed
glfwDestroyWindow(window);
// close GLFW library
glfwTerminate();
}
(4) Vertex shader triangles.vert Document code and comments
#version 400 core //OpenGL Color language version
layout( location = 0 ) in vec4 vPosition; // Save vertex position information
void main()
{
gl_Position = vPosition; // Copy the input vertex position to the specified output position of the vertex shader
}
(5) Slice shader file code and comments
#version 450 core
out vec4 fColor; // The color value corresponding to the slice
void main()
{
fColor = vec4(0.5, 0.4, 0.8, 1.0);
}
reference :
[1]The OpenGL Programming Guide 9th Edition:http://www.opengl-redbook.com/
[2]OpenGL Red Book Example Code:https://github.com/openglredbook/examples
[3]GLFW Source download - compile - Use :http://t.zoukankan.com/Doyoung-p-13690602.html
[4]OpenGL Programming Guide [ The first 9 edition ]
Artificial intelligence dry goods recommendation
Focus on technology sharing in the field of artificial intelligence
Game metauniverse
Focus on technology sharing in the game field
边栏推荐
- Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比
- [daily question] the next day
- [100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
- 全链路数字化转型下,零售企业如何打开第二增长曲线
- 距离度量 —— 杰卡德距离(Jaccard Distance)
- Meta universe chain game system development (logic development) - chain game system development (detailed analysis)
- 迷你高尔夫球场:伦敦休闲旅游好去处
- Transformation of thinking consciousness is the key to the success or failure of digital transformation of construction enterprises
- SLC、MLC、TLC 和 QLC NAND SSD 之间的区别:哪个更好?
- 使用CLion编译OGLPG-9th-Edition源码
猜你喜欢

Singapore summer tourism strategy: play Singapore Sentosa Island in one day

Redis (6) -- object and data structure

Obligatoire pour les débutants, cliquez sur deux boutons pour passer à un contenu différent

Exness in-depth good article: dynamic series - Case Analysis of gold liquidity (V)

Responses of different people in technology companies to bugs | daily anecdotes

Hospital online inquiry source code hospital video inquiry source code hospital applet source code

ICDE 2023|TKDE Poster Session(CFP)

聊聊电商系统中红包活动设计

【JVM调优实战100例】02——虚拟机栈与本地方法栈调优五例

故障排查:kubectl报错ValidationError: unknown field \u00a0
随机推荐
Page title component
R language ggplot2 visualization: gganimate package creates dynamic histogram animation (GIF) and uses transition_ The States function displays a histogram step by step along a given dimension in the
sql训练2
聊聊电商系统中红包活动设计
Hospital online inquiry source code hospital video inquiry source code hospital applet source code
Mysql高级篇学习总结7:Mysql数据结构-Hash索引、AVL树、B树、B+树的对比
Competence of product manager
How to enable the run dashboard function of idea
SQL training 2
Looking for innocence in New York -- a beautiful day at the discovery center of Legoland, New Jersey
R language ggplot2 visual Facet: gganimate package is based on Transition_ Time function to create dynamic scatter animation (GIF)
在纽约寻找童真——新泽西州乐高乐园探索中心的美好一天
Introduction to the paper | analysis and criticism of using the pre training language model as a knowledge base
[100 cases of JVM tuning practice] 02 - five cases of virtual machine stack and local method stack tuning
How to play when you travel to Bangkok for the first time? Please keep this money saving strategy
距离度量 —— 杰卡德距离(Jaccard Distance)
ORA-01455: converting column overflows integer datatype
Learn the knowledge points of eight part essay ~ ~ 1
R语言使用epiDisplay包的cox.display函数获取cox回归模型汇总统计信息(风险率HR、调整风险率及其置信区间、模型系数的t检验的p值、Wald检验的p值和似然比检验的p值)、汇总统计
学生抖音宣传母校被吐槽“招生减章”,网友:哈哈哈哈哈哈