Tag Archives: Computer graphics

[Solved] Errors encountered when using VS to write opengl code

Record the errors encountered when writing opengl code using vs:
problem:
error: the following is a new check for glut 3.0; Update your code.
after checking for a long time, it is found that this may be the reason why the portal
does not write the callback function of the window

Solution:
write the callback function yourself

glutDisplayFunc(&display);

Among them, display is the calling function written by yourself, for example:

glutDisplayFunc(DrawOval);//Draw callback function, glut mechanism, it will be executed when it feels the need to redraw

The drawOval here is the function I wrote to draw an ellipse

Visual studio 2019 + OpenGL environment configuration

Using the

    gl.hglu.hglaux.h

Download Directory:
https://download.csdn.net/download/boyinc0de/11171372
in

 
The following:

Include directory corresponding to downloaded files, unzipped include folder
The library directory corresponds to the downloaded files and the unzipped Library folder
 
VS2019 may report an error.
1> Glaux. Lib (tk.obj) : error LNK2019: Cannot resolve external symbol _sscanf, which is referenced in the function _GetRegistrySysColors@8
1> Glaux. Lib (tk.obj) : error LNK2019: Unresolvable external symbol _vsprintf, which is referenced in the function _PrintMessage
VS2015 compilation will cause this problem, the solution is in the project properties ->; The linker – & gt; Input – & gt; Add a dependency legacy_stdio_defines.lib to the attached dependency;
Here’s a reference:
https://blog.csdn.net/qqsqqsqqs318/article/details/58156094
 
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
In later experiments, we used the GLUT library, and I put the configuration procedure in the following:
https://www.jianshu.com/p/be32da974d8c
PS: I just put the.dll file in the Debug folder of the project where the.exe is located. I don’t want to copy everything to the system files
 

Vs2015 configuring OpenGL (glfw Library)

Recently to use OpenGL, in VS2015 configuration cost a lot of effort, now will be my results directly contribute to everyone, hope to need to configure OpenGL under VS2015 readers save some trouble.
Documents to prepare
Baidu cloud link: https://pan.baidu.com/s/1qZbcLtU password: f58o
PS: The tutorial gives you a 32-bit library. Baidu Cloud Resource is the 64-bit runtime I compiled later. The configuration process is similar to
Download the relevant header files

Download or compile the relevant library files
Here I used the library files compiled by Win32, that is, the Release of x86 platform, including the lib static library and the dynamic DLL library;

File storage
Put all the header and library files in one folder (I put them in the D:/freeglutlib folder);

Part program
1. Open VS2015, create a new Win32 console program, set the compilation environment as x86 or Win32, Release version;

2. Find the property manager and create a new property sheet under the corresponding compilation environment;

3. Select the VC++ directory ->; Include directory, library directory, just saved the header file and library file corresponding folder to add in


4, Compiler ->; Input – & gt; Attach a dependency, and type the DLL names of all the external libraries used

5. Add code in main file to test

Configure OpenGL development environment (glfw3 + glad) once and for all with visual studio

primers
There are many versions of OpenGL, we need to introduce additional third-party libraries to meet our usual rendering needs, which is more troublesome for students who just started learning.
I also met many many times behind the configuration of the tutorial, wasted time, also their technology and modern technology of OpenGL.
(2018), at the current time from learning OpenGL if glBegin () and a glEnd () that a is behind The Times, this tutorial is to demonstrate how to configure OpenGL3.3 over the environment.
> Learn the OpenGL tutorial: Learnopengl, you may need over the wall, there is a Chinese translation.
If you want to learn OpenGL quickly, here is the configured environment: (open it directly in VS2015 or above, Win7/10 test)
perlink: Resources
(> header files, lib files, DLLs used in the directory structure are also in this link)
The directory structure
The environment we configured is not only responsible for storing code and third party lib, but also some shader files and resource files, so we need to build a good directory structure.
The full configuration directory structure is as follows:

tr> <>> vsbuild> td>

/ table> <>d>
name

note

SRC

store code

external \ include

third-party library header files, Contains stb_image. J h, glad. J h, GLFW. J h, assimp. H such as

external \ lib

third-party libraries of lib

external \ DLL

third-party library DLL

resources

resource folder,
>
Focus on the folders under external\include
GLM OpenGL mathematical library, defined a lot of vector, matrix operations, concise and fast. GLFW is a cross-platform abstract library of window resources. Glad has different OpenGL implementations for different graphics card drivers, Glad helps us hide these differences and happily use OpenGL. STB_IMAGE lightweight library for reading images ASSIMP lightweight library for reading models
We have, so to speak, all the common components except the physics engine and sound control.
Now let’s construct the directory structure from scratch.
> First find an empty folder and create the following directory structure in it:

Instead of creating a vsbuild, VS will do it for us.
> Open Visual Studio and create an empty project. The project name is vsbuild.

After creation:

Next we need to configure lib, include to be introduced into our project.
Right-click on the vsbuild project and open the properties page:

Find the C/C++ Genral

note that the C/C++ option only appears when you create a new.cpp file)
E>the additional directory on the right:

Note that SolutionDir is a macro that represents the directory where VSBuild is located, so we can find External/Include relative to it.
(Type the information $(SolutionDir)… , external, include).
Similarly, select the additional library directory for Linker’s General

Open Edit:

In addition, open the Linker Input directory and enter the following values:



glfw3.lib
ad.lib
s>mage.lib
assimp.>
SolutionDir \external\lib
(here I compiled glad and stb_image into static libraries)
nally, because ASSIMP requires dynamic linking, we need to import the corresponding DLL into our project.
The easiest way to do this is as follows:

Select Debug and edit the environment entry:

The meaning of this line is to temporarily add the EXTERNAL \ DLL directory to the environment variable in debug mode so that we can successfully dynamically link.
After the configuration is complete, paste the following code into source.cpp and run.

#include <glad\glad.h>
#include <glfw\glfw3.h>
#include <iostream>


void framebuffer_size_callback(GLFWwindow* window, int width, int height);

void processInput(GLFWwindow *window);



// settings

const unsigned int SCR_WIDTH = 800;

const unsigned int SCR_HEIGHT = 600;



int main()

{

    // glfw: initialize and configure

    // ------------------------------

    glfwInit();

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);



#ifdef __APPLE__

    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // uncomment this statement to fix compilation on OS X

#endif



                                                         // glfw window creation

                                                         // --------------------

    GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);

    if (window == NULL)

    {

        std::cout << "Failed to create GLFW window" << std::endl;

        glfwTerminate();

        return -1;

    }

    glfwMakeContextCurrent(window);

    glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);



    // glad: load all OpenGL function pointers

    // ---------------------------------------

    if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))

    {

        std::cout << "Failed to initialize GLAD" << std::endl;

        return -1;

    }



    // render loop

    // -----------

    while (!glfwWindowShouldClose(window))

    {

        // input

        // -----

        processInput(window);



        // render

        // ------

        glClearColor(0.2f, 0.3f, 0.3f, 1.0f);

        glClear(GL_COLOR_BUFFER_BIT);



        // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)

        // -------------------------------------------------------------------------------

        glfwSwapBuffers(window);

        glfwPollEvents();

    }



    // glfw: terminate, clearing all previously allocated GLFW resources.

    // ------------------------------------------------------------------

    glfwTerminate();

    return 0;

}



// process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly

// ---------------------------------------------------------------------------------------------------------

void processInput(GLFWwindow *window)

{

    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)

        glfwSetWindowShouldClose(window, true);

}



// glfw: whenever the window size changed (by OS or user resize) this callback function executes

// ---------------------------------------------------------------------------------------------

void framebuffer_size_callback(GLFWwindow* window, int width, int height)

{

    // make sure the viewport matches the new window dimensions; note that width and 

    // height will be significantly larger than specified on retina displays.

    glViewport(0, 0, width, height);

}

The following window shows that the configuration is successful.

[OpenGL · error] visual studio 2019 reports an error. It is an external symbol gladloadglloader that cannot be parsed. This symbol is referenced in the function main

Errors encountered
Today before open write OpenGL rendering triangular program, found that have been submitted to the following error

when thought is a good start you don’t have links to files and library files, search on the Internet, and finally found the problem, is you don’t have the glad. C files added to the project.
The solution
Before remembering yourself to add glad.c file is passed in the source file ->; Create a new item, create a new glad.c file, and then copy the contents of the glad.c file from the other directory.

> By right-clicking the source file ->; Add an existing item ->;

OpenGL environment configuration under VS2010 / vs2012 / vs2015

Please read every word carefully.  
In order to learn “OpenGL Super Bibliography (Fifth Edition)” must configure OpenGL environment, is the so-called work to do its thing must first benefit its device. Through a lot of online configuration tutorial, have a lot of problems, but also has the essence of the detailed tutorial, such as a blog: http://www.zyh1690.org/build-opengl-super-bible-fifth-edition-development-environment/. While the tutorial is detailed, there are a few details that the blog doesn’t go into. Configuring the OpenGL environment must be careful and patient. Because a little oversight can cause the final configuration environment to fail. Although this is for the “Win7 X64 +VS2010” environment configuration process, but I in VS2012/VS2015 also built successfully, VS2012/VS2015 configuration OpenGL principle is also very simple, is one of the Microsoft Visual Studio 10.0 to add files into Microsoft Visual Studio 12.0 or Microsoft Visual Studio 15.0 to add related files.
Configure environment:
win7 X64 + Visua Studio 2010
win7 X64 + Visua Studio 2012
win7 X64 + Visua Studio 2015
Required configuration files and tools:

Baidu cloud disk Download Address:
Link: http://pan.baidu.com/s/1kVsKUGJ password: XXQQ
Link: http://pan.baidu.com/s/1slu9RK5 password: asj8
Here is the official setup:>; > > > > > > > > > > > > > > > > > > > > > > > Line & gt; > > > > > > > > > > > > > > > > > > > > > > > > Line & gt; > > > > > > > > > > > > > > > > > > > > > > > >

The FreeGLUT configuration

Open the x:\x\ FreeGlut-2.8.1 \VisualStudio\2010\ FreeGlut.SLN project project, (if you are configuring VS2015, you can select x:\x\…. \2015\ FreeGlut.SLN Project Project)

The solution is generated in Debug mode and Release mode, respectively. (You can generate only one. It is recommended to compile in debug mode without execution. If you run the pop-up black box, ignore it. 32-bit operating systems note that eventually, when running the code in Bluebook chapter01\ Block, if you encounter a problem with freeglut_static. Lib not being opened, you should choose Debug_Static mode to recompile and generate the required freeglut_static. Lib and add it to the specified folder.)
You will see the generated.dll and.lib files in the x:\x\ FreeGlut-2.8.1 \lib\x86 directory. Please add _d to the.dll and.lib files in the Debug directory to distinguish them later. As shown in figure:

 
X :\x\ FreeGlut-2.8.1 \ Include \GL: :\Program Files (x86)\Microsoft Visual Studio 10.0\VC\ Include \GL: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : :
Copy the.dll file in the x:\x\ FreeGlut-2.8.1 \ Lib \x86 folder (and the Debug folder) to the C:\ Windows&syswow64 directory (x86 to the System32 directory).
Copy the.lib file in the x:\x\ FreeGlut-2.8.1 \lib\x86 folder (and the Debug folder) to x:\x\Microsoft Visual Studio 10.0\VC\lib.
So now the FreeGlut is done!
(Once you’ve done this, you can code check.
Test 1: build Win32 console project, add test code, compile and run.
Test two: build Win32 console project, add test code, compile and run.

II. GLEW configuration
Copy the.h file in the folder x:\x\glew-1.11.0\include\GL to the directory x:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL.
Copy the.lib file in the folder x:\x\glew-1.11.0\lib\Release\Win32 to the directory x:\x\Microsoft Visual Studio 10.0\VC\lib.
Copy the.dll file from the x:\x\glew-1.11.0\bin\Release\Win32 folder to the C:\ WindowsSYSWOW64 directory. (If not, skip it.)
(Note that if VS2015 is supplied, you need to put the configuration file in x:\x\Microsoft Visual Studio 15.0…. C)

Third, GLUT configuration
Copy the.h file in the folder x:\x\ Glutdlls37Beta to the directory x:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\GL.
Copy the.lib file under the x:\x\ Glutdlls37Beta folder to the x:\x\Microsoft Visual Studio 10.0\VC\lib directory.
Copy the.dll file under the x:\x\ Glutdlls37Beta folder to the C:\ WindowsSYSWOW64 directory.
(Note that if VS2015 is supplied, you need to put the configuration file in x:\x\Microsoft Visual Studio 15.0…. )
4. Build GLTools library
Create a new GLTools Win32 project, as shown in the figure below:

 

First compile, (original here has error, below is I modify)
Copy the.cpp file (excluding glew.c file) in the x:\x\SB5\Src\GLTools\ Src directory to x:\x\ GLTools\ GLTools.
Copy the.h file (excluding the GL folder) in the x:\x\SB5\Src\GLTools\include directory to x:\x\ GLTools\ GLTools.
Right-click on the header file and the source file respectively and add ->; The existing item adds.h and.cpp files to the project. As shown in figure:

 
The compiler prompts are as follows:

The gltools.lib file was generated successfully. It can be viewed under the x:\x\gltools\Debug directory.
Copy the.lib file to the x:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib folder.
Copy the.h file to the x:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include folder (note that this is not the GL folder).
So gltools is OK.

Five, the test
Let’s test the environment using the examples given in the book. If the test is successful, then the OpenGL environment is ready.
The project of establishing TEST:


We use the example from Chapter 1 to test by copying all the files in the x:\x\SB5\Src\Chapter01\Block into the x:\x\test\test folder. Also right-click on the source file and add ->; The existing entries include the block.cpp file.
Adding Additional Dependencies (first figure) :(This way of adding dependencies only works for the current Test project. To make these.lib files available to other projects, you should add dependencies to the properties manager, as shown in the second figure below.


Compile and run the project, and the effect is as follows :(If there is an error in compilation, search the error information with Baidu Browser to find the corresponding solution. Or check out “Some special cases handling” at the end of this blog post for help.)
Press the space bar to transform the display effect, a total of six effects:






VI. Handling of some special cases:
Configuring the OpenGL environment exactly as described above will work on most computers. However, there are always exceptions. If the configuration fails, the following configuration details may help you solve the problem.
Case1: freeglut_static.lib could not open the problem
OpenGL SuperBibliography \SB5\SB5\ FreeGlut-2.6.0 \VisualStudio2008Static\Release FreeGlut_Static. Lib to X :\Program Files (x86)\Microsoft VisualStudio 10.0\VC\ Lib If you fail, try Plan 2.
Solution 2: Take a closer look at the FreeGLUT configuration section of this blog post, which is highlighted in bold red. Pay attention to configuration details.
case2: “math3d.h” : No such file or directory
C :\project\gltools\gltools\math3d.cpp(45): fatal error C1083: failed to open the “math3d.h” : No such file or directory header file.
Case3: UCrtBased. DLL missing
in Visual Studio 2015
Can follow this link: http://blog.csdn.net/so_geili/article/details/53009680, choose the “solution” to solve the problem.

Configuring OpenGL in Visual Studio 2015

This article is republished from Baidu Lesson: Configuring OpenGL in Visual Studio 2015





Program test:

#include "stdafx.h"
#include <GL/glut.h>


void init(void)
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glMatrixMode(GL_PROJECTION);
	gluOrtho2D(0.0, 200.0, 0.0, 150.0);
}

void lineSegment(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(0.0, 0.4, 0.2);
	glBegin(GL_LINES);
	glVertex2i(180, 15);
	glVertex2i(10, 145);
	glEnd();
	glFlush();
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowPosition(50, 100);
	glutInitWindowSize(400, 300);
	glutCreateWindow("An Example OpenGL Program");

	init();
	glutDisplayFunc(lineSegment);
	glutMainLoop();
	return 0;
}

Program running results:

Create an OpenGL project in codeblock

This semester’s graphics need to use OpenGL, but the teacher configured OpenGL in class is VS2010, I don’t know what is wrong with my computer. Several installs of VS2010 are useless. So I went online to find out how to configure OpenGL in Codeblock. But many of them are useless. Very not easy to find the method is feasible in this blog (assault delete) : http://blog.csdn.net/yang_7_46/article/details/24674849
The resources I also uploaded to: http://download.csdn.net/detail/qq_33276623/9468487
Specific configuration method (yes I was the screenshot. Face covering) : Ahah

How do you create the project once you’ve configured it?
1. The file – & gt; New – & gt; For the project, select GLUT Project

The following steps are done by themselves. This is it

You need to select MinGW, and the next step is to create it successfully.
If you want to add files to the Codeblock project, select the project -> from the top function bar; Just add it.

Configure OpenGL in CodeBlocks

There are many online tutorials, but some are easy to use and some are not.
There are two broad categories. One is that you don’t have to manually add libraries after you’ve configured them, but a New GLUT Project is needed to create a New Project instead of the usual Console Application. This category can refer to this document: https://wenku.baidu.com/view/7396dc8783d049649b66588c.html
Another type of configuration method, when configured, will be a New normal Console Application, but you will need to manually add the OpenGL library.
I chose the second category because I found that the console could not be tuned out of the configuration method of the first category, so I could not see the output of the console. Debug is very inconvenient, so I haven’t found a solution yet.
General reference is http://www.yalewoo.com/opengl_notes_2_use_opengl_in_codeblocks.html, but is not identical also, built after the project need to add one more libraries.

Steps:
Glut. h goes into the MinGW\include\GL directory of the compiler. .
glut32 lib in MinGW \ lib directory
glut32. The DLL into the C: \ Windows \ System in

Open the codeblocks create the console program, and then in the project to build the options – would add three static link library glut32 Settings. The lib, libopengl32. A, as well as libglu32. A, their paths in the lib folder of the compiler.

Installation and use of OpenGL based on CodeBlocks

1. The main process, in my collection. You can find the original blog directly.
2. Attention:
A libbgi.a file is also downloaded. It is installed under C: Program Files (x86)\CodeBlocks\MinGW\lib. Download Address:
http://www.3673.com/file/280472.html
Second:
Put the glut32.h file under the MinGw\include\GL directory
Put the glut32.dll file under the C:\Windows\ system32 directory (for a 64-bit operating system, put the file under the C:\Windows\SysWOW64 directory)
t the libglut32.a under the MinGw\lib\ directory
T> are the three full lines of the author. I just installed the second file in the wrong path and caused a lot of errors.
In addition: want to test your results immediately, here are some examples of application: https://blog.csdn.net/Halsey_/article/details/79684493

CodeBlocks configuring OpenGL

Download Windows environment GLUT, link: https://pan.baidu.com/s/1U43rth8-9W6AcP2zG3GFRw password: i2zu
Glut.h, Glut32.dll, LibGlut32.a, MSVCR70.dll

The following directory is mine, the specific operation pay attention to their own installation directory

1. Put Glut. h in F:\Program Files\ Codeblocks \ MingW \ Include \GL
2. Put libglut32.a in F:\Program Files\CodeBlocks\MinGW\lib
3. Place glut32. DLL in C:\Windows\System32 for 32-bit OS and C:\Windows\ Syswow64 for 64-bit OS
Then create a GLUT project

Then specify the GLUT location (this is just my location, notice your installation directory).

Online other people’s tutorials tutorials may be so far, but I have the following problems

You should start the code with a #include< windows.h> OK, but it looks like it’s going to be above the sentence GLUT


The last problem is an error that says “because msvcr70.dll……….. cannot be found” C:\Windows\System32 or C:\Windows\SysWOW64. These two directories should be the difference between 32-bit and 64-bit systems

Configuring OpenGL in Visual Studio

This semester to learn the graphics, to use C ++ to write, which is mainly used OpenGL, so first of all, to configure OpenGL in Visual Studio
1. Create a new C ++ console application. File – & gt; New – & gt; project

2. Then click Item ->; Manage the NuGet package

3. Browse here, type NupenGL and search

4. After downloading and installing both of them, import the header file at the beginning of the source program, and you can use it