Opengl basic learning topic (1) programming environment setup and opengl topic

Source: Internet
Author: User

Opengl basic learning topic (1) programming environment setup and opengl topic


Digress:

For the first time, I shared my blog with you on the blog site, where the water is located, where the typos are located, where the environment is exchanged, and where the criticism is made.

I used to write a technology blog post in the Baidu space, and Baidu closed the whole space without saying anything. at that time, I felt a bit chilling. I just want to get rid of it. The Director is old. the venue should be changed.

I want to write an oepngl basic learning topic, mainly because the resources on the Internet are a little old and many of them cannot run. I bought a red book <OpenGL programming guide version 8th> and read it again, I think it is a bit professional, and there are many optimizations and technical core points.

It is also a code snippet. It is still difficult to learn from outsiders like yourself. You need to make up the basic api for freeglut and glew programming. For these reasons, I want to summarize my own opengl.

Share it with graphics-loving friends. There is also an online basic opengl learning material that is carved in a model, but the model is a bit old. The code is wrong. Someone needs to change it a little bit.

 

Question:

Here is the freeglut and glew Development Environment built on Window. At least before, the two libraries used are the latest on the official website.

Freeglut is a freeglut-3.0.0 version, freeglut is compatible with the glut graphics library of the main API. glew is its encapsulation of its cross-platform. I personally think that cross-platform chewing head is more.

Really get up or need some effort. The latter version is adopted by the glew-1.13.0.

 

Configure the environment.

1. The basic header files and library files of the above two databases

Http://download.csdn.net/detail/wangzhione/9172439

Download * lib and *. dll to the root directory of the project.

Click the link and add it to the additional dependent library as shown in the following figure,

In the module file, we recommend that you.

Right-click the project and choose "VC ++ directory"> "include directory", as shown in figure

Perform the following operations:

 

In this way, your environment will be OK, and the rest will need to include these header files in the project. My approach is as follows:

Mainly look at the structure of the module above. You can create A virtual directory, shift + alt + A to include those header files. The library files must be in the root directory, that is, under the project folder.

The above section describes how to build freeglut and glew environments on VS. This is too troublesome.

 

2. It is a little troublesome to build the environment above. Every time this is done, development on Windows cannot stand it.

To put it bluntly, the preceding path inclusion method is equivalent to the gcc command on linux.

Gcc-Imodule/freeglut-Imodule/glew-L.-l ........

Here we will continue to provide a small detail. for static and dynamic libraries with the same name as-l, gcc will first find the dynamic library and add the-static option to find the static library.

The following method is to use VS to automatically add a project template. Here I created a. simplec template with VS2015 as follows:

Http://download.csdn.net/detail/wangzhione/9172445

Download the file and place it under the VS2015 Project template. The basic path format is

C: \ Users \ {computer name} \ Documents \ Visual Studio 2015 \ Templates \ ProjectTemplates

After creating a project (shift + Ctrl + N), you can add that project.

 

3. For the above C basic learning development framework, the source code project file is as follows:

Http://download.csdn.net/detail/wangzhione/9172455

I have the opportunity to write several blog posts separately to present my current design ideas.

This simple basic C development framework is suitable for learning and playing.

Supports multithreading, reading simple configuration files, logging, simple strings, csv files, and json files. Common macros and common data structure encapsulation with simple constraints.

Here are some other things that are purely personal.

1) We recommend that you learn to install the latest IDE on Windows. By default, the debugging function of Visual studio is really poor.

It is really life-saving. Next time I have a chance to share my thoughts on how to use Pelles C to develop programs. It will also work together. It is easy to break down when debugging occurs.

2) use vim + gcc + makefile to work on Linux. Try cmake again next time.

Microsoft's tools are really easy to use. Every time I work on a black window full screen, I really want to ask, is this really suitable? Why don't we try it?

Develop a Visual Stduio for Linux 2048 for Linux to save cainiao like me.

 

Here, the environment is OK. Here is a test DEMO, as shown below. Do not always ask why, or stick to codeing more because there are not so many reasons.

# Include <glut. h> // The void display (void) function of the screen rendering function; // The simple configuration of the glut environment int main (int argc, char * argv []) {gluinit (& argc, argv); gluinitdisplaymode (glu_rgb | glu_single); gluinitwindowposition (100,100); gluinitwindowsize (400,400); glucreatewindow ("the first OpenGL program "); // set the drawn function maid (display_02); // execute the glut loop fig (); return 0;} void display (void) {glClear (GL_COLOR_BUFFER_BIT ); // draw a rectangle glRectf (-0.5f,-0.5f, 0.5f, 0.5f); glFlush ();}

 

The function of this program is to draw a White Rectangle in the center of a black window.

For the above Code Format, I will share it again next time if I have the opportunity. For C naming and writing, the genre of the format can be talked about for a week. Few people have said these questions, it is basically an experience after catching, rolling, and crawling too much.

Let's talk more here. For people with poor C skills, you can read a friend article I added and learn more. he is more real, but the code is more rigorous and suitable for laying the foundation.

GarbageMan => http://www.cnblogs.com/pmer/

There are also cloud-based blog posts. To improve the performance, you can check them. If you are pragmatic, you can check the above blog posts.

Each row of statements is described below.

First, you need to include the header file # include <glut. h>, which is a header file contained in freeglut.

Then look at the main function.

Int main (int argc, char * argv []). This is a main function with command line parameters. Have you ever seen it? If you have never seen any other comrades, please read more books and wait until you understand them.

Note that all the statements in the main function, except the last return, start with glut. The functions starting with glut are all functions provided by the GLUT toolkit. The following describes several functions used.

1. gluinit: Initialize the GLUT. This function must be called once before other gluts are used. The format is relatively rigid. You can copy this keyword according to the format of gluinit (& argc, argv.

2. Set the display mode of the glutInitDisplayMode. In the display mode, the ng_rgb color indicates that the RGB color is used, and the corresponding value is the ng_index (indicating that the index color is used ). Glu_single indicates that a single buffer is used, and the corresponding value is glu_double (dual buffering is used ). For more information, Google. Of course, there will be some explanations in future tutorials. (About how to use FQ to share a blog post next time)

3. Set the position of the window on the screen.

4. It is also simple to set the window size.

5. Create a window based on the information set above. The parameter is used as the title of the window. Note: The window is not displayed on the screen immediately after it is created. You need to call the glumainloop function to view the window.

6. Set a function to map a graph. The function is called. (This statement is not accurate enough, but it may be difficult for beginners to understand it. Let's talk about it for the time being ).

7. A message loop is implemented using the glumainloop. (This may not be quite understandable for beginners. Now you only need to know that this function can display a window and will return it only after the window is closed .)

In the gludisplayfunc function, we set "Call the display function when drawing is required ". The display function is used for drawing. Observe the three function calls in display and find that they all start with gl. These functions starting with gl are all OpenGL standard functions, which are described below.

1. glClear: Clear. GL_COLOR_BUFFER_BIT indicates to clear the color. The glClear function can also clear other things, but it is not described here.

2. glRectf: Draw a rectangle. The four parameters represent the horizontal and vertical coordinates of the two points on the diagonal line.

3. glFlush: ensure that the previous OpenGL commands are executed immediately (instead of waiting them in the buffer ). Its role is similar to that of fflush (stdout.

 

The basic configuration here is OK. If you have any questions, you can leave a message or search for it.

There are certainly some mistakes in the blog. You are welcome to correct them. We will continue sharing this article if you don't work overtime next time. You are welcome to add friends for discussion, just in Beijing. Single Male programmers

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.