OpenGL notes (a)

Learning LearnOpenGL, note-taking experience as follows:

Notes (answer below)

The role of 1.glEnalbleVertexAttribArray function?

2. Create a series of operations VBO's?

3. Specific opened VertexAttribArray, how to set it?

4.GLunit What does it mean?

The completion of the third supplementary question yesterday unfinished.

6. What is a shader? What is a GPU?

7. Specifically picture triangle specific function?

8.glEnalbeVertexAttribArray (0) and glDisableVertexAttribArray (0) 0 inside What does it mean?

9. There is a problem, why glVertexAttribPointer parameters inside, did not specify GL_BUFFER_ARRAY it?

10. The code is as follows


	 GLFWwindow *window1;
	 window1 = glfwCreateWindow(500, 500, "First Window", NULL, NULL);
	 glfwWindowHint(GLFW_VERSION_MAJOR, 3);
	 glfwWindowHint(GLFW_VERSION_MINOR, 3);

	//  glfwMakeContextCurrent(window1);
	 if (glewInit() != GLEW_OK)
	 {
		 cout << "Failed to initialze glew!!" << endl;
		 glfwTerminate();
		 return -1;
	 }

Found a problem later if glfwMakeContexCurrent comment out a line of code, will complain:
Here Insert Picture Description
Why?

11. After calling glVertexAttribPointer, there is a very important function, glSwapBuffers, missing painting it out

12.GLSL C language and what is the difference in terms of compiling and running?

13. Today the picture is very basic triangle, at the prompt box appears such a situation:

Here Insert Picture Description
glEnableVertexAttribArray () and glEnableVertexArrayAttrib () What is the difference?

Last night found a good video station B class, to go with a lot of things to figure out, and now all the functions to create a blank window are basically figure out.
Here difficult place to do a summary.
14. glSwapBuffers (GLFWwindow * window) what's the use?

15.glColor and glClearColor function?

16. Why do you want to set a program heap and stack, with the entire space to store the data is not good, think of threads and processes, how to explain?

17. expand at issue yesterday, which is part of the thread private and public, which is part of the process private and public?

18.C ++ to write a string like this

const char * string1="Hello World";

If you want to write two lines of how to get, is that right?

const  char *string1="  Hello
                                       World  ";

19. The VAO and Vertex attribute What is the relationship?

20. There is a problem, since VertexAttrib deposit with the VAO, the data layer of the Index dug from the VBO placed among the VAO tier 0, why even if I do not create it VAO can draw a triangle?

21.OpenGL inside the triangle drawn default is clockwise or counterclockwise? How to make OpenGL display only display only the front or the back

22. The small tip, how a key multi-line comment ?

23. how to draw a triangle becomes a wireframe mode?

24. The front triangle 23 learned how to become a wireframe mode, then how the quadrilateral inflicted wireframe model?

25. How do the current time time into a sine function with time-dependent?

26. The Warning 1
Do not use it declared in a Uniform GLSL, so may result in significant errors.

27. The input and output vertex shader and fragment shader requirements?

28. float a=0; if(a==0) cout<<"this is true“;There are no problems?

29.C ++ being given of how to use try and catch statements?

30. When do I need to use try and catch statements do, why not return -1 it?

31. read files on the disk from OpenGL, specific file transfer process?

32.ifstream, fstream and ofstream What does it mean?

33. There is a class thrown exception, as shown below:
Here Insert Picture Description

Notes answers

2019.1.3
1. Role: the vertex attributes for opening

CPU is the first look at how the transfer vertex data to the GPU, the CPU is transferring data directly into the memory of the GPU, such as the establishment of a VBO (vertex buffer objects) to store in the GPU vertex information, but the question is, though data transferred to the internal GPU, but the pass past data for the default shader is not visible , that itself is a vertex shader attributes of these properties, for performance reasons, is off by default, so if you want to get we need attributes, you need to open the corresponding attributes of the vertex shader to use this function.
Therefore, with prior vertex shader, this function must be used.

GLuint VBO;
glGenBuffer(1,&VBO);
//OpenGL有很多缓冲对象类型,需要进行绑定操作
glBindBuffer(GL_BUFFER_ARRAY,VBO);    //将对象绑定在状态机上,这个类型就绑定了当前的VBO
glBufferData(GL_BUFFER_ARRAY,sizeof(original_data),original_data,GL_STATIC_DRAW);//从CPU传入了GPU

PS: Note that this binding means that after binding the VBO, any operation is configured to operate GL_BUFFER_ARRAY VBO currently bound.

glBufferData last parameter is a parameter type, a total of three:
GL_STATIC_DRAW: The data plotted substantially constant;
GL_DYNAMIC_DRAW: change a lot of data;
GL_STREAM_DRAW: each drawing data changed;
therefore the latter two modes, the data will typically be placed GPU memory section of high-speed writing. If you simply draw a triangle with the first line.

3. How to set the specific vertex attributes, where the need to use a function glVertexAttribPointer ();
void glVertexAttribPointer (GLuint index, GLint size, type GLenum, GLboolean Normalized, a stride of GLsizei, GLvoid const * pointer);

This function has six parameters,
size: 1,2,3,4 preferably only (initial value is 4), represents the number of each vertex attributes such as, size spatial coordinates (x, y, z) is 3, color RGBα was 4.
type: i.e. data type (initially GL_FLOAT), such as (X, Y, Z) data type GL_FLOAT.

4.GLuint, is glu int, which is similar GLfloat, apply resources to OpenGL, OpenGL usually only returns an integer handle.

2019.1.4

5.VertexAttribPointer, meaning that a dispenser vertex attributes, note that it deals with BO (buffer object), is not a pointer, an index value is index specifies the type of vertex attribute array, format and location.

VertexAttribPointer (index, size, of the type, on Normalized, a stride of, offset)
index: the index value, namely handle vertex array?
On Normalized: the need for normalization, the need is GL_TRUE, otherwise GL_FALSE.
stride: step, if it is 0, the vertex attributes are selected closely spaced together.
offset: refers to the offset, so what does it mean?
offset in bytes, the offset refers to the offset address of the first byte begins reading:
Here Insert Picture Description

6. In the above compiled applet GPU, GPU (Graphics Processing Unit) graphics processing unit.

; 7.glDrawArrays (MODE int, int First, int COUNT)
COUNT MODE to use the most basic Mode, GL_TRIANGLES, first point subscript 0, count is the number of points to be drawn, so that in this mode, given It should be a multiple of three. For example
glDrawArrays (GL_TRIANGLES, 0,3);

8 . The number 0 is the index value Index, as to why is 0? The official explanation is as follows:

glVertexAttribPointer(
   0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
   3,                  // size
   GL_FLOAT,           // type
   GL_FALSE,           // normalized?
   0,                  // stride
   (void*)0            // array buffer offset
);

That predetermined OpenGL, VertexPosition the layout is 0, 1 VertexColor the layout coordinate index is 0, the color index is 1, which is a predetermined attribute.

9. There is an implicit relationship: different types of binding OPENGL different BO, but glVertexAttribPointer is the function for GL_BUFFER_ARRAY always pointing BO bound under this type, so no separate and then set the rendering mode.

2019.1.5

10. Remember, the context of the operation was set before initialization glew, personally feel that contex must be loaded in, the specific reasons remain.

11. See 14

12.GLSL is running side edge compiler, and C is the first to compile and run.

13.glEnableVertexAtrribArray () array means is enabled vertex attribute, an attribute array is enabled, the attribute value is determined by the index Index, the former only one parameter, while glEnableVertexAtrribArray () array is enabled vertex attributes, as shown below:
Here Insert Picture Description
This function requires two parameters, should enable a vertex array property of a particular VBO.
The number two function parameters are not the same, here is the first to enable vertex attribute array Index, do not confuse.

2019.1.6
14.glSwapBuffers translates as meaning the exchange buffer, since the buffer plus s, which means more than a buffer, so here involves the concept of a double-buffered, about double buffering English explained as follows:
Double Buffer:
the When an application draws in a single buffer image might display flickering issues. This is because the resulting output is not drawn in an instant, but drawn pixel by pixel and usually from left to right, top to bottom.Because this image is not drawn in an to the User at The Still the while the Instant being rendered to, the Result May Contain at The artifacts.To circumvent THESE AND DELINQUENCY, the Application window the Apply A Double Buffer for rendering.The Front Buffer the contains the Output at The Final Image that IS AT Shown at The Screen, All the while at The Rendering Commands at The Draw the Back BufferSoon AS at The Rendering All the .as Commands are Finished WE swap at The Buffer to the Back at The Front Buffer, SO IS Instantly at The Image at The displayed to the User, Removing All at The aforementioned artifact.
Summarize the Chinese explained as follows:
Since computer graphics is a painting by one pixel take time, if a single buffer, we may see a specific painting process, will cause the screen flashes and other issues, but our customers do not need to see the specific process you draw, so in order to solve this problem, here with a double buffering when, with the two memory areas to store data, the buffer is divided into front and back buffer, the front buffer is used to display content on the screen, it is then used to draw the buffer, then the beginning of each frame, the two buffer exchange, so the buffer and can draw new content.

15. As mentioned earlier, because a double buffering mechanism, each frame of the picture to be re-switching cache (Of course, if static_draw each specific frame or not to re-draw I do not know), if each frame to be reloaded, so before you draw on the screen contents need to be removed, that is, the use of glClear () function
glClear () function has three parameters:
GL_COLOR_BUFFER_BIT
GL_DEPTH_BUFFER_BIT
GL_STENCIL_BUFFER_BIT
first is to remove the color buffer.
The glClearColor function is a subroutine to set specific parameters glClear function (so I understand), and to set clear screen color, should be placed in front of glClear function settings.

2019.1.7
did not write a summary, written tomorrow

2019.1.8
16. First solve some problems yesterday:
Stack is a unique thread, heap is our public space , stack space is divided into local heap and global heap, the former is not assigned, which is already allocated

17. A thread private: register, thread stack, program counter.
Threads share: heap, global variables, static variables, the address space of
the process private: address space, heap and stack, registers, global variables,
the process of sharing: process directory, code segments, public data, process ID
18. The written wrong, would look like this :

const char* string1 = "Hello"
              " World";

19.VAO is used to select where the data sort stored VBO, the VAO can have many columns (manual testing found 16 bar (0 to 15)):
for each column is stored vertex attributes, i.e. vertex attributes, so
glVertexAttribPointer () function role is to dig out the specific data VBO, put it in his first index column saved.
In addition to the sixteen bar properties, as well as the last column is the place of EBO
Here Insert Picture Description

#version 330 core                                     
layout(location=0)  in vec3 aPos;        
void main(){                          
     gl_Position=vec4(aPos.x ,aPos.y, aPos.z,1.0f); } 
;

Here layout (location = 0) refers to the index from the layer VAO call.

20.remain

2019.1.9
21. counterclockwise triangle is drawn, OpenGL default values while painting the front and back, if you want,
eliminate back then requires only two lines of code

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);

22. When selected, Ctrl + K + C .

23. This increase can be initialized after GLEW:

glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);

Note that GL_LINE not GL_LINES.

2019.1.10 learned Fu teacher shader (1) Courses
24.remain

     float time=glfwGetTime();
     float res=sin(time)/2+0.5f;`

2019.1.11
27.The vertex shader should receive some form of input otherwise it would be pretty ineffective.(必须输入) The vertex shader differs in its input, in that it receives its input straight from the vertex data. To define how the vertex data is organized we specify the input variables with location metadata so we can configure the vertex attributes on the CPU. We’ve seen this in the previous tutorial as layout (location = 0). The vertex shader thus requires an extra layout specification for its inputs so we can link it with the vertex data.
The other exception is that the fragment shader requires a vec4 color output variable(必须输出), since the fragment shaders needs to generate a final output color. If you’d fail to specify an output color in your fragment shader OpenGL will render your object black (or white)(否则默认为黑色或者白色).

28. There are problems with floating-point numbers can not be compared of 0, double type can not be compared with 0, if the comparison should have to write:

float a=0;
if(a>-0.000001&&a<0.000001)

2019.1.12
29.C ++ exception is thrown uses three keywords: try the catch and throw
so try to check whether there is an exception, catch and capture abnormal position to deal with it, throw an exception is thrown

try{
//包含可能异常的语句
}
catch (类型名[形参名])    //捕获特定类型的异常
{
//处理异常的语句
}

for example:

#include <iostream>
void f(int b) {
	int a = 5;
	if (b == 0)
		throw "Failed to divide zero!";

	std:: cout << a / b << std::endl;

}

int main()
{
	try
	{
		f(2);
		f(0);
	}
	catch (const char* s)  //如果捕捉到了此类型的throw
	{
		std::cout << s << std::endl;
	}

}

It feels a bit like a switch case statement, catch capture different types of exceptions.

Extra attention, you can enter ... three point represent any type, as follows:
Here Insert Picture Description

30. Most cases are under direct

if(特殊情况)  return ;

With frequency may be low, so what time to use it?
When their package when some functions, with others to give, do not need to let others see when the internal code to achieve,
do not return directly to the end of the function, but in unusual ways thrown.

Figure 31. The
Here Insert Picture Description
start reading the file to disk within FileBuffer, but due to a disk file formats vary, so he should convert the file stream StringBuffer all the way, but the CPU only recognize the char type, do not know the string, so to the string replaced by gray line caught char .

32.ifstream: input file stream
fstream: file stream
ofstream: output file stream

Defined 33.exception (exception) class as follows:

class exception{  
    public:  
        exception () throw();  //构造函数  
        exception (const exception&) throw();  //拷贝构造函数  
        exception& operator= (const exception&) throw();  //运算符重载  
        virtual ~exception() throw();  //虚析构函数  
        virtual const char* what() const throw();  //虚函数  
    }

Above what function is a virtual function, which put the string constant, if the output when there is no

Unknown Exception

Usage is as follows

#include <iostream>
using std::exception;
void f(int b) {
	int a = 5;
	if (b == 0)
		throw exception();
   std:: cout << a / b << std::endl;
}

int main()
{ 
	try{
		f(2);
		f(0);
	}
	catch (exception &a)
	{
		std::cout << a.what() << std::endl;
		std::cout << "cuowu" << std::endl;
	}

}

I do not define the content of exception inside, so the output is as follows:
Here Insert Picture Description
But if the change

void f(int b) {
	int a = 5;
	if (b == 0)
		throw exception("False!");
	std:: cout << a / b << std::endl;
}

Output:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/alexhu2010q/article/details/86658373