Tag Archives: OpenGL

Ubuntu: CodeBlocks compile OpenGL super Dictionary (5th Edition) instance

This article is written by XHZ1234 (Xu Hongzhi), reprint please indicate the source.
http://blog.csdn.net/xhz1234/article/details/38349623
Recently in the OpenGL super bible fifth edition, the system for Ubuntu, want to pass the Codeblocks running instance of the book, encountered many problems, have been solved, now share operation steps are as follows:

1. Establish a basic compilation environment
sudo apt-getinstall build-essential
 
2. Install OpenGL Library
sudo apt-getinstall libgl1-mesa-dev

Install OpenGL Utilities
sudo apt-getinstall libglu1-mesa-dev

4. Install OpenGL Utility Toolkit
sudo apt-get installfreeglut3-dev

5. Install the Codeblocks

Install the Code::Blocks IDE in the Ubuntu Software Center

6. Create a new Codeblocks project
New Console Application Project –>; Select C++ Language, such as the project name HelloWorld

7. Include OpenGL/ GLUT related link libraries
Project a Build Options a linkerSettings
Add file: libgl. so libGlut.so libGlut.so
[1 ~ 7 steps can refer to blog http://blog.csdn.net/jarvischu/article/details/8226938, step 6 must establish the Console application and is a c + + language]

8. Download freeglutAndGLTools
The address is: http://download.csdn.net/detail/xhz1234/7707213,
. Will download GLToolsandFreeglut. Tar. Xz decompression freeglut – server and GLTools, these two files in the directory and copy the HelloWorld directory to the new project.

9. Add the example code
In the case of SphereWorld4 in the OpenGL Superbib (Version 5), copy the contents of SphereWorld4.cpp to main.cpp in the new project (or you can remove main.cpp and copy SphereWorld4.cpp directly to the HelloWorld project), and then Codeblocks adds these files.

10. The modified SphereWorld4. CPP
The code is shown in red:

// SphereWorld.cpp
// OpenGL SuperBible
// New and improved (performance) sphere world
// Program by Richard S. Wright Jr.

// SphereWorld.cpp
// OpenGL SuperBible
// New and improved (performance) sphere world
// Program by Richard S. Wright Jr.

<span style="color:#FF0000;">#include "./GLTools/include/GL/glew.h"
#include "./GLTools/include/GLTools.h"
#include "./GLTools/include/GLShaderManager.h"
#include "./GLTools/include/GLFrustum.h"
#include "./GLTools/include/GLBatch.h"
#include "./GLTools/include/GLMatrixStack.h"
#include "./GLTools/include/GLGeometryTransform.h"
#include "./GLTools/include/GLTools.h"
#include "./GLTools/include/StopWatch.h"
</span>
#include <math.h>
#include <stdio.h>

#ifdef __APPLE__
#include <glut/glut.h>
#else
#define FREEGLUT_STATIC
#include <GL/glut.h>
#endif

#define NUM_SPHERES 50
GLFrame spheres[NUM_SPHERES];


GLShaderManager		shaderManager;			// Shader Manager
GLMatrixStack		modelViewMatrix;		// Modelview Matrix
GLMatrixStack		projectionMatrix;		// Projection Matrix
GLFrustum			viewFrustum;			// View Frustum
GLGeometryTransform	transformPipeline;		// Geometry Transform Pipeline

GLTriangleBatch		torusBatch;
GLBatch				floorBatch;
GLTriangleBatch     sphereBatch;
GLFrame             cameraFrame;

//
// This function does any needed initialization on the rendering
// context.
void SetupRC()
    {
	// Initialze Shader Manager
	shaderManager.InitializeStockShaders();

	glEnable(GL_DEPTH_TEST);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	// This makes a torus
	gltMakeTorus(torusBatch, 0.4f, 0.15f, 30, 30);

    // This make a sphere
    gltMakeSphere(sphereBatch, 0.1f, 26, 13);

	floorBatch.Begin(GL_LINES, 324);
    for(GLfloat x = -20.0; x <= 20.0f; x+= 0.5) {
        floorBatch.Vertex3f(x, -0.55f, 20.0f);
        floorBatch.Vertex3f(x, -0.55f, -20.0f);

        floorBatch.Vertex3f(20.0f, -0.55f, x);
        floorBatch.Vertex3f(-20.0f, -0.55f, x);
        }
    floorBatch.End();

    // Randomly place the spheres
    for(int i = 0; i < NUM_SPHERES; i++) {
        GLfloat x = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        GLfloat z = ((GLfloat)((rand() % 400) - 200) * 0.1f);
        spheres[i].SetOrigin(x, 0.0f, z);
        }
    }


///
// Screen changes size or is initialized
void ChangeSize(int nWidth, int nHeight)
    {
	glViewport(0, 0, nWidth, nHeight);

    // Create the projection matrix, and load it on the projection matrix stack
	viewFrustum.SetPerspective(35.0f, float(nWidth)/float(nHeight), 1.0f, 100.0f);
	projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());

    // Set the transformation pipeline to use the two matrix stacks
	transformPipeline.SetMatrixStacks(modelViewMatrix, projectionMatrix);
    }


// Called to draw scene
void RenderScene(void)
	{
    // Color values
    static GLfloat vFloorColor[] = { 0.0f, 1.0f, 0.0f, 1.0f};
    static GLfloat vTorusColor[] = { 1.0f, 0.0f, 0.0f, 1.0f };
    static GLfloat vSphereColor[] = { 0.0f, 0.0f, 1.0f, 1.0f };

    // Time Based animation
	static CStopWatch	rotTimer;
	float yRot = rotTimer.GetElapsedSeconds() * 60.0f;

	// Clear the color and depth buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    // Save the current modelview matrix (the identity matrix)
	modelViewMatrix.PushMatrix();

    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.PushMatrix(mCamera);

    // Transform the light position into eye coordinates
    M3DVector4f vLightPos = { 0.0f, 10.0f, 5.0f, 1.0f };
    M3DVector4f vLightEyePos;
    m3dTransformVector4(vLightEyePos, vLightPos, mCamera);

	// Draw the ground
	shaderManager.UseStockShader(GLT_SHADER_FLAT,
								 transformPipeline.GetModelViewProjectionMatrix(),
								 vFloorColor);
	floorBatch.Draw();

    for(int i = 0; i < NUM_SPHERES; i++) {
        modelViewMatrix.PushMatrix();
        modelViewMatrix.MultMatrix(spheres[i]);
        shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(),
                                transformPipeline.GetProjectionMatrix(), vLightEyePos, vSphereColor);
        sphereBatch.Draw();
        modelViewMatrix.PopMatrix();
        }

    // Draw the spinning Torus
    modelViewMatrix.Translate(0.0f, 0.0f, -2.5f);

    // Save the Translation
    modelViewMatrix.PushMatrix();

        // Apply a rotation and draw the torus
        modelViewMatrix.Rotate(yRot, 0.0f, 1.0f, 0.0f);
        shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(),
                                     transformPipeline.GetProjectionMatrix(), vLightEyePos, vTorusColor);
        torusBatch.Draw();
    modelViewMatrix.PopMatrix(); // "Erase" the Rotation from before

    // Apply another rotation, followed by a translation, then draw the sphere
    modelViewMatrix.Rotate(yRot * -2.0f, 0.0f, 1.0f, 0.0f);
    modelViewMatrix.Translate(0.8f, 0.0f, 0.0f);
    shaderManager.UseStockShader(GLT_SHADER_POINT_LIGHT_DIFF, transformPipeline.GetModelViewMatrix(),
                                transformPipeline.GetProjectionMatrix(), vLightEyePos, vSphereColor);
    sphereBatch.Draw();

	// Restore the previous modleview matrix (the identity matrix)
	modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();
    // Do the buffer Swap
    glutSwapBuffers();

    // Tell GLUT to do it again
    glutPostRedisplay();
    }


// Respond to arrow keys by moving the camera frame of reference
void SpecialKeys(int key, int x, int y)
    {
	float linear = 0.1f;
	float angular = float(m3dDegToRad(5.0f));

	if(key == GLUT_KEY_UP)
		cameraFrame.MoveForward(linear);

	if(key == GLUT_KEY_DOWN)
		cameraFrame.MoveForward(-linear);

	if(key == GLUT_KEY_LEFT)
		cameraFrame.RotateWorld(angular, 0.0f, 1.0f, 0.0f);

	if(key == GLUT_KEY_RIGHT)
		cameraFrame.RotateWorld(-angular, 0.0f, 1.0f, 0.0f);
    }

int main(int argc, char* argv[])
    {
	gltSetWorkingDirectory(argv[0]);

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(800,600);

    glutCreateWindow("OpenGL SphereWorld");

    glutSpecialFunc(SpecialKeys);
    glutReshapeFunc(ChangeSize);
    glutDisplayFunc(RenderScene);

    GLenum err = glewInit();
    if (GLEW_OK != err) {
        fprintf(stderr, "GLEW Error: %s\n", glewGetErrorString(err));
        return 1;
        }


    SetupRC();
    glutMainLoop();
    return 0;
    }

11. Compile and run as follows:



End of text!
Add:
1) OpenGL super bible code download address: http://www.starstonesoftware.com/files/
Code that uses Super Bibliodek directly will not compile at Codeblocks. The above steps will work fine.
2) During compilation, there are many alarms, which fall into two categories:
2-1)

||=== Build: Debug in TestForLove2 (compiler: GNU GCC Compiler) ===|
/home/xhz/Program/TestForLove2/GLTools/src/GLTools.cpp||In function ‘GLbyte* gltReadBMPBits(const char*, int*, int*)’:|
/home/xhz/Program/TestForLove2/GLTools/src/GLTools.cpp|1062|warning: converting ‘false’ to pointer type ‘GLbyte* {aka signed char*}’ [-Wconversion-null]|
/home/xhz/Program/TestForLove2/GLTools/src/GLTools.cpp|1074|warning: converting ‘false’ to pointer type ‘GLbyte* {aka signed char*}’ [-Wconversion-null]|
||=== Build finished: 0 error(s), 2 warning(s) (0 minute(s), 3 second(s)) ===|

Change false to NULL in the corresponding location of gltools.cpp

2-2)

||=== Build: Debug in TestForLove2 (compiler: GNU GCC Compiler) ===|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h||In constructor ‘GLBatch::GLBatch()’:|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|127|warning: ‘GLBatch::nNumTextureUnits’ will be initialized after [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|126|warning:   ‘GLuint GLBatch::nNumVerts’ [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/GLBatch.cpp|57|warning:   when initialized here [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|135|warning: ‘GLBatch::pTexCoords’ will be initialized after [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|119|warning:   ‘GLuint GLBatch::uiVertexArray’ [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/GLBatch.cpp|57|warning:   when initialized here [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|129|warning: ‘GLBatch::bBatchDone’ will be initialized after [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|125|warning:   ‘GLuint GLBatch::nVertsBuilding’ [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/GLBatch.cpp|57|warning:   when initialized here [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|125|warning: ‘GLBatch::nVertsBuilding’ will be initialized after [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/../include/GLBatch.h|122|warning:   ‘GLuint* GLBatch::uiTextureCoordArray’ [-Wreorder]|
/home/xhz/Program/TestForLove2/GLTools/src/GLBatch.cpp|57|warning:   when initialized here [-Wreorder]|
||=== Build finished: 0 error(s), 12 warning(s) (0 minute(s), 4 second(s)) ===|

The reason for the warning is

constructor variables are initialized in a different order than the member variable is defined in class GLBatch

The order of member variables in the GLBatch definition in the code is as follows:

class GLBatch : public GLBatchBase
{
          ...
    protected:
	GLenum		primitiveType;		// What am I drawing....
        
	GLuint		uiVertexArray;
	GLuint      uiNormalArray;
	GLuint		uiColorArray;
	GLuint		*uiTextureCoordArray;
	GLuint		vertexArrayObject;
        
        GLuint nVertsBuilding;			// Building up vertexes counter (immediate mode emulator)
        GLuint nNumVerts;				// Number of verticies in this batch
        GLuint nNumTextureUnits;		// Number of texture coordinate sets
		
        bool	bBatchDone;				// Batch has been built
 
	
	M3DVector3f *pVerts;
	M3DVector3f *pNormals;
	M3DVector4f *pColors;
	M3DVector2f **pTexCoords;
	
};

and in the class initializer list defined as follows:

GLBatch::GLBatch(void): nNumTextureUnits(0), nNumVerts(0), pVerts(NULL), pNormals(NULL), pColors(NULL), pTexCoords(NULL), uiVertexArray(0),
	uiNormalArray(0), uiColorArray(0), vertexArrayObject(0), bBatchDone(false), nVertsBuilding(0), uiTextureCoordArray(NULL)

in order to eliminate the above alarm, only the two order is unified, I will be the order of the member variables in a GLBatch made changes.

With the above changes are synchronized to the freeglutAndGLTools, address is: http://download.csdn.net/detail/xhz1234/7707213 compressed package in the corresponding files.

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

OpenGL learning summary (1)

GLVERTEX2F (GLFLOAT, GLFLOAT) is a function that displays two parameters in the window. If you want to display two parameters in the window, the values of the parameters range from 0.0 to 1.0.

glBegin(GL_LINES):
vertex2f *(A);
glVertex2f*(A);
glVertex2f*(B);
glVertex2f * ©;
AB and CD… There will be linear connections between, but no linear connections between BC and DE
GlBegin (GL_LINE_STRIP) :
glVertex2f * (A);
glVertex2f*(B);
glVertex2f * ©;
AB and CD… There will be linear connections between BC and DE

Summary of problems encountered in compiling opengl code

one
Error 1 C2381: “exit” : redefinition; __declspec(noreturn) “This type of error is caused by the wrong order of reference header files,
Solutions:
Switch the inclusion order of the header file:
#include < GL/glut.h>
#include < stdlib.h>

#include

stdlib.h>    
#include < GL/glut.h>
Refer to the link https://www.cnblogs.com/rainbow70626/p/10732342.html
 
two
E:\OPENGL_Project\lightwithView\lightwithView\lightInViewSpace. Obj lightwithView”
“Error 13 error LNK2019: Cannot resolve external symbol __imp__glClearColor@16, which is referenced in function _main E:\OPENGL_Project\lightwithView\ lightWithview \ lightinViewSpace. Obj lightwithView”
Glew32s.lib is a static library, not a dynamic library, so Glut. h is added.
#include < GLEW/glew.h> It must be preceded by #define GLEW_STATIC
 
 
three
LINK: warning LNK4098: default library ‘MSVCRT’ conflicts with other libraries Please use/NODEFAULTLIB: the cause of the library “is trying to incompatible library links, such as SOIL link libraries, originally provided by the website is libSOIL. A file, but directly use the static library files may output of the error, and error” unparsed external symbol __alloca in function _stbi_zlib_decode_noheader_buffer reference “, this time as long as the SOIL’s own project on its own compiler to generate the corresponding SOIL. The lib files, Replace libsoil. LIB file, problem solved!
https://blog.csdn.net/iscassucess/article/details/8302264 this link explain more clearly, you can refer to.
 

Common problems of shadow map in OpenGL

Shadow maps are a common technique in games,
The principle is to view the entire scene from the light space with the light viewing matrix (binding the depth cache with the frame cache), and the resulting scene is not rendered
The second drawing, the depth buffer into the shader, all point transformation to the light space, the z coordinates, and the depth of the original cache value contrast, if the resulting value is less than the value of the depth buffer is proved that the pixels in the most close to the rear of the light source location, so this point can’t render, reason for shadow covered place.
This is what I get, the light source is rotated around (0,0,0) with a radius of 50. In the middle is a physical model. The entire lighting system is the simplest (an improved version of Feng’s lighting).

Problem 1. Boundary problem: there is a plane in front of the light source, the space outside the plane is the area affected by light, and the area inside the plane is the area not affected by light.

The problem is very simple. In the light space analysis, the light space, like the view space, has a cone:

The areas outside the cone that are not located on the upper ledge are all clipped out of the light space.
To make the cone black outside the edge, since the second time the shader calls the depth cache, it will also call some areas in the depth cache, which will result in the wrong result on the boundary.
To solve this problem, when setting the depth cache, you need to set all colors outside the bounds to black :


And that will give you the right answer.
Problem 2. Texture error
Textures are rendered in striped red, blue and green colors.
This is because the texture is not formatted correctly, the image is formatted in RGBA format, but the texture is formatted in RGB format, which will result in the wrong result:

As shown in the figure above, setting the image format to GL_RGBA will solve this problem when reading the image from the library

Problem 3. Follow the tutorial, but there are no shadows, the whole scene is bright
If there is no compiler error in the shader, please check whether the two matrix Settings are consistent (that is, whether the matrix of optical space is directly passed into the second shader).
In the second shading, set the observation matrix to the light space matrix to see if the whole scene can be seen in the light space observation matrix.
If the whole scene is not visible in light space, the entire depth cache is infinite (i.e. 1.0F), and all the points are in front of the occlusion, so you will see the whole scene lit up.
Question 4. According to the tutorial to write, there is no shadow, the whole scene is dark
The problem may be that your light source is so close to the model that the whole scene is completely blocked by the model from the light space. Another possibility is that the first rendering of the depth cache was not written,
This also results in the equivalent of a large flat surface in front of you.
Question 5. Where there is shadow, there is light, and where there is light, there is shadow
The reason for this problem is that there is a logic error in the shader of the second rendering, and the shadow is 1, which means there is a shadow (for example in Learnopengl tutorial). Therefore, it is necessary to use (1-shadow) in the final calculation of Feng’s illumination.
Multiplied by stolid and ambient, not shadow
Problem six. A layer of gray, according to the tutorial to eliminate but not the effect
The gray is caused by the principle defect of Shadowmap. It is possible that multiple adjacent pixels of the rendered graph correspond to the depth value in the same depth cache, resulting in the wrong corresponding of the depth value, so there will be streaks.
If the tutorial minus the value of a fixed doesn’t work, minus the value can be more a little bit small. This means that you draw volume is very big, I draw when I was led to this situation, this is because the tutorial is a very small unit to draw, so it’s bigger than the offset, but I draw the unit is very big, (100.0 f) so I need to reduce the value of the more, you can test several times, each time reduce an order of magnitude, by the way, I use a value of 0.00001, this is a very small value, the results after the application of the this value is true.

There are some other problems, such as the resolution is not enough to lead to the edge is not clear and so on, this kind of problem can find some anti-aliasing method to solve, is to take the average edge.
If you have a problem can leave a message at the bottom, you can also find me to source.
(to be continued….)

Solve the problem of VC6.0 open crash and OpenGL glut32.lib library

VC6.0 Open crashes
Recently, I learned OpenGL and tried to debug with VC6, but found that after installing VC6, ADD and OPEN projects could not be used, so I summarized the simplest solution. This method is very common, just for the sake of going directly to my blog to find it after I encountered it again. (1) First copy the FileTool. DLL file to the folder “VC6 installation path “\Common\MSDev98\AddIns

FileTool. DLL available download address: http://download.csdn.net/detail/yangxkl/4061390
(2) manually register the DLL regsvr32 “VC6 installation path \Common\MSDev98\AddIns\FileTool. DLL “in CMD

(3) Right click on the toolbar, Customise… -> Add-ins and Macro Files

Select the Filetool Developer Studio Add-In add-on,
Then click Close

add after the success, the VC on the interface of two more green menu button, an A, one is O, implements the increase and the two button to open the file.

(4) If the module “xxx. DLL “is loaded, but the call to DllRegisterServer fails, it is a problem to add the DLL by hand.

:

program – attachments – command prompt, click the right mouse button on the “command prompt”, select “run as an administrator” command, this time will open the DOS command window, now as normal type Regsvr32 xxx. DLL, can be registered successfully.

This will successfully increase the DLL file. To this VC6.0 open crash problem is solved.

Fatal error LNK1104: cannot open file “glut32.lib” : fatal error LNK1104: cannot open file “glut32.lib” : fatal error LNK1104: cannot open file “glut32.lib”

Glut. lib is a standalone library that does not come with standard OpenGL, and can be downloaded online
Download Glut-3.7.6-bin.zip (Glut32.lib Glut32.dll Glut.def Glut.h)
Available glut – 3.7.6 – bin. Zip download address: http://download.csdn.net/download/dragoo1/1148263
Put the glut32.lib file in the VC6 interface and go to the library files path of tools-options-dictinaries… In the vc98/lib directory, place glut32.dll in C :/ Windows /system32.
All OK.
The.h,.dll, and.lib files in “Glut-3.7.6-bin” are copied to the root directory of the project folder and are included in the “#include” Glut.h “method.
Everything is OK!

Three, attached VS2008 to add header directory and Lib directory method
H file directory:
in turn, click on the “Project – configuration properties – C/C + + – regular”,
Project – & gt; Property-> C/C++-> General-> Additional Include Directories

b :
G> “Project — Configuration Properties — Linker — General” and put the Directories
project> in the Additional Include Directory. ProPerty-> Link-> General-> Additional Include Directories
>, go to “Linker Directories” and add lua51.lib
put ->; Additional Dependencies
or
# pragma comment (lib, “lua51. Lib”)

Summary of OpenGL simple solar system simulation

For some herself also don’t know why, I have a strange tenderness in c + +, always have the urge to want to use c + + programming task, but I really don’t like to always inside the black box of the console input and output, and the operation mechanism of MFC temporarily and I don’t know, one is a string file has been completed, looking at halo, OpenGL is accord with the need, and there is a glut can help implement simple forms in the console, speak quite enough as a simple to use, complex use later to say again.
I am completely a beginner, with reference to the “OpenGL Introduction Tutorial” this document and some references on the network can be scraped together to complete this simple solar system model. (here to thank the makers of this tutorial and the sharer, I feel to write quite good, there is a download on the Internet, I am from baidu library to get, they also passed a to the resources) why is the solar system model?Because I love it, and a lot of people have done it, and I don’t understand it, but there’s a code to learn. Needless to say, the first on a renderings:

The starting point of any project should be a requirement analysis. The requirement is very simple, which is to display a model that looks like the solar system on the screen, and just look like it. It takes time and effort to make an accurate model of the solar system, and no one pays for it. Then the design phase, as object-oriented programming, look for the object, the eight planets in the solar system as well as the sun itself, in order to look more beautiful point, track should also be mapped, so the object has two, all objects to achieve a draw method, is used to draw themselves, to design a myObj parent class can be easily performed as part of the paint job, I think now that each orbit to a certain object, then the track can be used as a private attribute of the object, it should be a dependency. The class diagram is as follows:

The basic information for the star ASTER includes the radius of the star, the revolution period revolution_solar, the revolution period self, the orbit orbit, and the revolution radius distance. Orbit has only one radius property. There are also some auxiliary properties that are defined in the implementation and are not listed in the class diagram.
With the class diagram, you can enter the coding stage, the first need to configure the development environment, I am using VS2010, development is using OpenGL, download address Baidu Google, I do not remember the original download address, passed a copy to the resources inside. Tutorial there said to be integrated development libraries to vs inside, but I don’t like it, don’t often use it is not necessary to change the development environment, as long as it is good to set a single project, the DLL file to the operation of the generated files,. H file saved to the project folder,..lib file loaded in the code should be able to use relative paths, but I don’t know where the base path is temporarily, so chose to set the attributes of the project, particular way is:
Right-click the project name in the Solution Explorer and select Properties ->; Linker-> General, add an absolute lib directory to Additional Librarydirectories. The lib file is loaded using #pragma comment (lib).
There are many examples in the tutorial, and each knowledge point is also very clear, do not repeat. Inside I met a little problem when system is realized in lesson 5 day month, if you use the tutorial to the parameters of the inside, in the window is what also can’t see, but if I ten times to reduce the parameters of the unified, can appear normal, though I searched some articles of coordinate transformation, but at present still don’t know why will appear this problem, if such as morally scaling should not appear different results?Doesn’t OpenGL accept parameters that are too large?
Said a little bit about the questions about the gluLookAt function, may be my personal problem, in understanding the function of the time a little effort, this function has nine parameters, divided into three groups, the first group is about the viewpoint of movement, a viewpoint is initially at point (0, 0), if not after the perspective projection transformation of coordinates, then draw the images will appear in the view’s location, similar to someone put something in your eyes, things just don’t see behind, can move through the first coordinate, then draw the solution to the object, But the advantage of Glulookat is that you don’t have to calculate the position of every object. You can view it from any Angle. It doesn’t matter if you just plot on the plane of the xyz axis, but what if you want to see the whole system at 45 degrees or 75 degrees?The position of each object is not easy to calculate. The way I understand this function works is that the developer first draws the whole system in the coordinate system, and then realizes the change of observation Angle through this function, and OpenGL automatically calculates the relative position of each object. This function must be placed before the other coordinate changes, and I feel that it is executed in the last order of the system drawing. The above is irresponsible conjecture, without any theoretical support, hereby declare…
Well, going a bit too far, the second set of parameters are the coordinates of the center of the viewpoint. The perspective projection itself is a four-prism, and the line between the viewpoint and the center is the same as a perpendicular from the vertex to the bottom.
The third parameter is the direction, that is, what do you think of the observer, the tutorial says from the point of (0, 0) to the point of attachment to determine positive direction, such as if set to (0, 0), is similar to normal viewing screen, (0, 1, 0) means the person is in upside down the screen, (0, 0, 1) said looked down at the keyboard, (0, 1) said from behind the display looked down at the keyboard…
There are still some problems with lighting and material Settings, we will talk about it later. The whole project has been uploaded to resources, please download it if necessary.
The first time you set up the project, you mistakenly selected Windows Application, which can be found in Properties ->; Linker-> system-> Subsystem changes to Console.
Modify the icon of the Console program to add resource->; Open Resource. H and set the ID of your icon to a minimum. To open Resource. H, open the.rc file (select View Code) and then open it in an include&lt file. resource.h> Select Open Document.

Summary of problems encountered in using OpenGL in QT

Configure environment VS2015 + QT5.9

: Error LNK2019: Unable to parse the external symbol – **.
: Error LNK2019: Unable to parse the external symbol – **.
solution
en cmake, put BUILD_SHARED_LIBS on the box, recompile to generate glfw3.lib and glfw3dll. DLL, add them to Qt’s pro, compile to pass.
Problem – Glad include
in Pro after configuration Glad path, add

#include <glad/glad.h>

If the position is not appropriate, an alarm will appear:

error: C1189: #error:  OpenGL header already included, remove this include, glad already provides it

containing glad must precede all penGL *** h>rs.
GlDrawElements ()
call function drawelements () e> :

Error - 
RtlWerpReportException failed with status code :-1073741823. Will try to launch the process directly

1. ***Pointer s>uffer error, vertex index out of bounds reference vertex array;
br bb3 GlbindVertexArray (0)

GlbindV>xArray (0)

GlbindVertexArray (0)

GlbindVerTexArray (0)

GlbindVerTexArray (0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0);
br> <>>



3. Call makeCurrent()fore binding VAO.
(To be continued)

OpenGL step pit record

OpenGL pit record
The 3D model is loaded with OpenGL RBO texture cache

3D model loading
When working with 3D models, we often create an FBO first, and the FBO is associated with Texture and RBO. The first time we rendered it, we rendered it directly to the FBO associated texture, then went through the other texture filters and displayed it again.
There are a couple of caveats here.
Rendering must be associated with an RBO. Turn Depth Test on before rendering off-screen and always turn it off after rendering off-screen. Do another render operation, otherwise render black screen texture will appear.

OpenGL RBO
Sometimes when OpenGL uses the depth buffer, the rendering effect disappears completely, and that’s probably because the depth buffer has been turned off.
The name of the
GLDepthMask – Enables or disables write depth buffers
C specification
void glDepthMask( GLboolean flag);
parameter
flag
Specifies whether the enabled depth buffer can be written. If flag is GL_FALSE, the depth buffer write is disabled. Otherwise, it can be enabled. The initial state is to enable deep buffer writes.
describe
GLDepthMask specifies whether the enabled depth buffer can be written. If flag is GL_FALSE, the depth buffer write is disabled. Otherwise, it can be enabled. The initial state is to enable deep buffer writes.
Related Gets
GL_DEPTH_WRITEMASK glGet parameters
See also
GLColorMask, GLDepthFunc, GLDepThrangef, GLStencilMask
copyright
https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glDepthMask.xml
https://blog.csdn.net/flycatdeng
Texture cache
To create a texture cache, you must specify the size of memory for the texture.

public static int createTextureObject(int textureTarget, int width, int height) {
        int[] textures = new int[1];
        GLES20.glGenTextures(1, textures, 0);
        GlUtil.checkGlError("glGenTextures");

        int texId = textures[0];
        GLES20.glBindTexture(textureTarget, texId);
        GlUtil.checkGlError("glBindTexture " + texId);

        GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameterf(textureTarget, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
        GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
        GLES20.glTexParameteri(textureTarget, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
        GlUtil.checkGlError("glTexParameter");
        GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
        return texId;
    }

Big hole in using OpenGL on Mac OS

Be free and at leisure started to research OpenGL, went to buy the Little Red Book 8 edition, the content of the book is based on Windows, and Mac can use the version is very low, OpenGL is up to 4.1, GLSL is 1.2 for me.
When we ran the first demo, we had a problem. The book used a FreeGLUT (a third-party library that can be used across platforms), and a FreeGLUT library on the Mac would not be able to compile the shader, so there were two ways to solve it
1: Use your own #include <; GLUT/GLUT.h> Instead of, and in glutInitDisplayMode (GLUT_RGBA | GLUT_3_2_CORE_PROFILE); Adds the specified version to 2. Use another third-party library, GLFW, to set the version number, which can be cross-platform

[learning opengl 22 step by step] – OpenGL importing 3D models with assimp Library

Tutorial 22
OpenGL imports 3D models using the ASSIMP library

Original: http://ogldev.atspace.co.uk/www/tutorial22/tutorial22.html
CSDN full version column: http://blog.csdn.net/column/details/13062.html


background
Through the previous learning we have achieved a lot of good results, but we are not good at creating complex models, you can imagine through the code to define every vertex position and other properties of the object is not feasible. A box, pyramid or simple surface mapping is fine, but what about a three-dimensional face?In fact, in games, in some commercial game applications, the mesh of the model is created by artists using modeling software such as Blender,Maya,3ds Max, etc. These software provide powerful tools to help artists create complex models. After the model is created, it is saved into a file. 3D model files are available in many formats, such as OBJ format. The 3D model file contains the entire geometry definition of the model, which can then be imported into the game engine (if the game engine can, of course)

[181124] VC + + use OpenGL to draw 3D graphics example source code

Download the source code
In VC++6.0 using OpenGL drawing 3D graphics example source code, source code is more complex, it can draw 3D three-dimensional renderings, cuboids, cubes, etc., its function is similar to a simple 3D drawing tools, there are other functions, you can download a compilation to explore what it is!
Source download address: click to download
Alternate download address: click download