One of the opengl tutorials: creating a form

To build an opengl environment, you can see my previous tutorials 

A tutorial on building a simple OpenGL environment under Visual C++ - Programmer Sought

opengl has other language versions, and the idea of ​​creating graphics is all the same, you can refer to

Use the opengl function to complete the drawing of the form 

#include<GL/glut.h>

void Display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glRectf(-0.5f,-0.5f,0.5f,0.5f);
	glFlush();
}

int main(int argc,char *argv[])
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(400, 400);
	glutCreateWindow("OpenGLTest");
	glutDisplayFunc(&Display);
	glutMainLoop();
	return 0;
}

after execution 

1.#include<GL/glut.h>

GLUT header files for Opengl

2.glutInit

Complete the initialization process, called once before the rest of the code executes

Appears if not called

 Function <glutCreateWindow> called without first calling 'glutInit'

3.glutInitDisplayMode

Set display mode

Which indicates that the RGB color mode and single buffer mode are used

 These are the modes, and the operators are combined into different flags. I will talk about the specific contents in the future functions.

4.glutInitWindowPosition

Sets the position of the form relative to the screen

5.glutWindowSize

Set the size of the form

6.glutCreatWindowSize

After the form is created, the parameter is the title of the form, but in principle, the window will not be displayed immediately, and it needs to be called later

glutmain can see the window clearly

Like in the UE engine, CreateWidget needs AddToView in the future to render the created window to the screen, but in fact, this form has a copy in the memory.

6.glutDisplayFunc

Register a function, when needed, this function will complete the drawing

7.glutMainLoop

Call the relevant functions in a loop, and then the window can be displayed

8.glClear

Indicates that explicit caching is required

where GL_COLOR_BUFFER_BIT clears the color

There are other caches that will be discussed in detail later.

  • GL_COLOR_BUFFER_BIT: The currently writable color buffer

  • GL_DEPTH_BUFFER_BIT: depth buffer

  • GL_ACCUM_BUFFER_BIT: Accumulated buffer

  • GL_STENCIL_BUFFER_BIT: Stencil buffer

9. glRectf

Draw a rectangle, the first two parameters represent the coordinates of the upper left corner of the rectangle, and the last two parameters represent the coordinates of the lower right corner of the rectangle

10.glFlush

The OpenGl function is forced to be executed within a limited time. In single buffer mode, the objects will hit the screen one by one.

Guess you like

Origin blog.csdn.net/qq_36653924/article/details/127267744