Tag Archives: visual studio

Vs2015 + OpenGL environment configuration

The article from http://jingyan.baidu.com/article/d5c4b52bca5005da560dc5d6.html
http://www.linuxidc.com/Linux/2013-02/78959p2.htm
Look at both of them if I don’t make sense

Download the GLUT library http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
(If you can’t get out, remember over the wall. I gotover the wallfrom BBB1 and downloaded it directly in the browser.)

Copy the static function libraries Glut. lib and Glut32.lib into the lib folder of the file directory after extracting them
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\lib

Will glut. DLL, glut32 DLL this two dynamic library file into the operating system directory under the C: \ Windows \ system32 folder (32-bit system) or ‪ C: \ Windows \ SysWOW64 (64 – bit systems).
For compatibility, it is best to copy the corresponding files in both directories.

Copy the extracted header file Glut. h into the following directory:
X:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ Include \GL

Tip: If there is no GL folder in the incluce directory, you will need to create it manually

Verification method:
Create a blank Win32 console application

2,
Add the include directory at the beginning of the code
#include < GL/glut.h>

3. Then you can edit your own OpenGL program

4,
For example: Copy the following code into the newly configured VS

#include < GL/glut.h>
#include < stdlib.h>
#include < math.h>
#include < stdio.h>
static int year = 0,spin=0, day = 0;
static GLint fogMode;
const int n = 100;
Const GLFloat R = 1.0F;
Const GLFloat Pi = 3.1415926536 F;

void DrawCircle()
{

Int I;
glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_LINE_LOOP);

for (i = 0; i < n; ++i)
{
GlColor3f (1.0, 0.0, 0.0);
glVertex2f(R*cos(2 * Pi/n*i), R*sin(2 * Pi/n*i));
}

glEnd();
glFlush();
}

void init(void)
{
GlFloat Position [] = {0.5, 0.5, 3.0, 0.0};

glEnable(GL_DEPTH_TEST); // prevent occlusion
glLightfv(GL_LIGHT0, GL_POSITION, position);
GlEnable (GL_LIGHTING);
glEnable(GL_LIGHT0);
{
GLFloat Mat [3] = {0.1745, 0.01175, 0.01175};
glMaterialfv(GL_FRONT, GL_AMBIENT, mat);
Mat [0] = 0.61424; Mat [1] = 0.04136; Mat [2] = 0.04136;
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat);
Mat [0] = 0.727811; Mat [1] = 0.626959; Mat [2] = 0.626959;
glMaterialfv(GL_FRONT, GL_SPECULAR, mat);
GlMaterialf (GL_FRONT GL_SHININESS, 0.6 * 128.0);
}

glEnable(GL_FOG);
{
GlFloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};

fogMode = GL_EXP;
glFogi(GL_FOG_MODE, fogMode);
glFogfv(GL_FOG_COLOR, fogColor);
GlFogf (GL_FOG_DENSITY, 0.35);
glHint(GL_FOG_HINT, GL_DONT_CARE);
GlFogf (GL_FOG_START, 1.0);
GlFogf (GL_FOG_END, 5.0);
}
GlClearColor (0.5, 0.9, 0.9, 1.0); Fog color/* * /

}

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GlColor3f (0.0, 1.0, 1.0);
GlPushMatrix (); // Remember your position
GlutSolidSphere (1.0, 20, 16); /* Draw solar radius, 20 longitude, 16 latitude */
GlRotatef (spin, 0.0, 1.0, 0.0); // Rotate around a vector at a given Angle (positive is counterclockwise)

GlTranslatef (2.0, 1.0, 0.0);

GlRotatef (spin, 1.0, 0.0, 0.0);// revolution
GlRectf (0.1, 0.1, 0.5, 0.5);

GlColor3f (0.0, 0.0, 1.0);
GlutWireSphere (0.2, 8, 8); /* Draw the first asteroid */
GlColor3f (1.0, 0.0, 0.0);
GlTranslatef (2.0, 1.0, 0.0);

Glrotatef (2 * spin, 0.0, 1.0, 0.0);
GlutSolidSphere (0.5, 16, 8);

glPopMatrix(); // Return to the original position

glutSwapBuffers();
}

void spinDisplay(void)
{
spin = spin + 2;
if (spin > 360).
spin = spin – 360;
glutPostRedisplay();
}

void mouse(int button,int state,int x,int y )
{
switch (button)
{
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(spinDisplay);
break;
case GLUT_MIDDLE_BUTTON:
if (state == GLUT_DOWN)
glutIdleFunc(NULL);
break;
default:
break;
}
}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GluPerspective (60.0, (GLFloat)w/(GLFloat)h, 0.5, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GluLookAt (0.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}

void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case ‘d’:
day = (day + 10) % 360;
glutPostRedisplay();
break;
case ‘D’:
day = (day – 10) % 360;
glutPostRedisplay();
break;
case ‘y’:
year = (year + 5) % 360;
glutPostRedisplay();
break;
case ‘Y’:
year = (year – 5) % 360;
glutPostRedisplay();
break;
case 27:
exit(0);
break;
default:
break;
}
}

int main(int argc, char** argv)
{
glutInit(& argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(400, 400);
glutInitWindowPosition(100, 100);
GlutCreateWindow (” OpenGL Programming — Yang Chao “);

init();
//glutDisplayFunc(DrawCircle);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);

glutMainLoop();
return 0;
}

5,
http://jingyan.baidu.com/album/d5c4b52bca5005da560dc5d6.html?picindex=5
So we have the picture

The simplest course of configuring OpenGL in vs2015

This may be the simplest configuration of OpenGL related library method, this semester needs to learn graphics, so the Internet to find a variety of configuration OpenGL method, found that many people are copied to copy, many methods are wrong. Otherwise, the PC environment is different and various.lib file lookup errors appear in the configuration. Also many methods need to configure the external environment, is also troublesome. Today I will introduce my own method, do not need to consider the computer environment, convenient and simple.
1. Upgrade to VS2015
I am using VS2015. I do not know about the previous version, nor do I know whether it can be used, so I suggest you to upgrade to 2015. After all, do you use the new version or not?
2. Open VS2015 and create a new Win32 project (won’t create the wall to go).
Name it whatever you want, place it whatever you want.
3. Use NUTGET
This step is the most important and the only step in the configuration process.
vs2015 toolbars -> NuGet Package Manager-> Manage Nuget Packages for solution
The diagram below

And then you see something like this

Search the Browse window for any library you want. For example, here I want to configure glew and freeGLUT, I’ll search glew and then click Install at the top.
When configuring FreeGLUT, remember to select the second one. In fact, you can look at the installation amount, and select the one with the highest installation amount as the safest install.
4. Test

#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
void init()
{
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
}

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(800, 480);
    glutInitDisplayMode(GLUT_RGBA);

    glutCreateWindow("opengl");

    glewInit();

    init();

    glutDisplayFunc(display);

    glutMainLoop();
    return 0;
}

Run this code, if run successfully indicates that the configuration is successful, do not need any reference code what, super convenient!!
if you’re running failure is your problem, it’s ok with me (low ˇ ∀ ˇ “)

Solve the problem of visual studio console flashback

On the top navigation bar, click “Project” ->; “Properties” – & gt; ‘Configure Properties’ –>; “Linker” –>; “System” – & gt; “Subsystems (there is a drop-down icon on the right side of the window)” –>; SUBSYSTEM:CONSOLE -> drop down box select ‘/SUBSYSTEM:CONSOLE’ -> Finally “confirm” –>; Click on the top right corner of “File” –>; “Save it all.”

The problem of flash back by pressing enter window when debugging or executing program in Visual Studio C

In the process of learning C with Visual Studio, we sometimes finished typing the code and found that the program could execute as well. But is it ever frustrating to press the enter key to execute the next command in the program and see the window flash back?Don’t worry. Just type the following simple code.
Just add the last line:
system(” pause “);
, don’t forget “; “Oh.
# include< stdio.h>
#include< stdlib.h>
main()

y>oplaceholder0;
*************;
*************;
system (” pause “); // Don’t forget the semicolon
}

Flash back after vs compiler running, processing method

How to solve the problem of flash back!!!!!!
I habitually deal with this problem in three ways
— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — –
1, system (” pause “);
2, getchar ();
3, Ctrl + F5
Let’s discuss the pros and cons of each separately: Welcome to the land of the Kings
System (” pause “) : need to include the preprocessing header #include< stdlib.h> ||#include< windows.h>
Usage: put return (); Before the return statement, otherwise there is no meaning
Advantages: solve the flashback problem, small side effects
Disadvantages: call system function, large memory overhead

Getchar () :

Usage: put return (); Before the return statement, otherwise there is no meaning
Advantages: low overhead, receive a character to end the program
Cons: Use it on a case-by-case basis, because getchar (); You need to accept a string to represent the end, and some functions explicitly need to accept a string as the return value, if you use getchar (); To solve the flashback problem, which can be confusing and introduce errors when the program is running.
can see, although can solve the running results of the flashback problem, but in the processing is completely different, although in the operation is also approximately the same, but in the memory, CPU and other levels, overhead is sometimes different, so you can choose according to your preferences for a way for you !!!!! System (” pause “) is recommended; This way, the introduction and processing of files is also more careful, if there is a heavy use of system functionality is, of course. windows.h> #include< stdlib.h> Of course, it is suitable for those who use a lot of library functions

 

Why does the result screen flash when visual studio runs the program?

When the console application in VS is running, the result screen will flash, whether using F5 or Ctrl + F5, and the result will not be visible. There are a lot of ways on the Internet, which is to add a pause statement to the program at the end or to get user input from the console statement. There’s a better solution:

Right click on your project entry, select the last item “Property/Properties” on the pop-up menu, and in the left column, find “Configuration Properties”

-> The linker – & gt; System, after clicking on the System item, subSystem in the right column configuring the value of the subSystem to “Console “.

After doing this, press Ctrl+F5 again and the program will stop at the console screen and prompt you to “Press any key to continue.” That’s the perfect solution.

Solution to the problem of console flash in vs2017 runtime

 
F5 is the command to start debugging, Ctrl + F5 is the command to start debugging (not debugging). If you change the command to Ctrl + F5, you can display the output normally and “Press any key to continue… “One word, and the problem is settled.
However, some people will find that after pressing Ctrl + F5, the program will still flash, so you can try the following method to solve this problem:
① Right click on the name of your project on the right and select the property at the bottom.


② select the configuration properties in turn ->; Connector – & gt; system

We locate the SUBSYSTEM on the right, click the down arrow on the right and select the CONSOLE

Finally make sure to save, you can try again after the operation by pressing Ctrl + F5 to run ~
There’s actually another way to do it, in return 0; Enter system (” pause “) on the previous line;

Three methods of how to remove the flashback of running result box in VS

First of all, we will often encounter the situation of running the results after coding in VS, and then suddenly flashing back, which is very bad, high for half a day, nothing to see. And I don’t know how to solve it.
Now, here are three ways to do it:
The first two, you probably know.
1 & gt; That’s when return 0; I’m going to do a getchar (); Getchar is waiting for input, so it effectively stops the result screen running;
2 & gt; Similar to the first method, in return 0; Pause a system(“pause”); The statement;
3 & gt; This is a little bit trickier. So first let’s go over how to create a C file. This is a simple one, but it will be used in this method: Go to New – Project – Win32 Console Empty Project – Type File Name – View – Solution Explorer – Source Files – Type Name, C. And when we get there, we’re done. Solution in the solution explorer, right-click the solution explorer, select properties – configuration properties – linker – system – a SUBSYSTEM, the SUBSYSTEM to CONSOLE (\ SUBSYSTEM: the CONSOLE), with respect to ok, this does not need to input, the SUBSYSTEM click on the right side of the blank area, there will be a drop-down options, then click “ok” to continue to write files, continues to run, you will find that yi, amazing.
The advantage of the third method is that it is more cross-platform. If your computer has this problem and someone else doesn’t, it will inevitably run wrong. But the disadvantage of this is that every time you write a file you have to change it.
I hope I can help you.

Visual studio console program output window flashed by

Write at the front:
This blog post introduces a little annoying problem solving that isn’t a bug. Programming with Visual Studio often uses the console output window, but there is always a situation where the window flashes past and it is difficult to see the output of the program. Here, I write a blog post to record it, so as not to forget or make similar mistakes in the same type of problem.
Solution:
1. In the last line of the program, return 0, add system(” pause “) or getchar(); It solves some problems, which I often do when I do some OJ tests in order to test in my IDE;
2. Don’t Press F5 to run the program, Ctrl + F5 instead, a window will be displayed like this: “Press any key tocontinue…” The words. The reason is that F5 is in Debugging mode, while CTRL +F5 is in Start Without Debugging mode. I found this on the Internet. Can really solve the problem, but their lack of practical theoretical knowledge to support, so in the future to read a lot of attention to the process.

Flashback problem of output window of visual studio 2017 console program

When you first come into contact with Visual Studio, most people will write a Hello World program to try. Some people will find that the output window will flash past after execution, and there is no “Press any key to continue”. This has happened in Visual Studio 2008, 2010, 2012, 2015, and now 2017, and some people might do it one of two ways:
Add system(“pause”) or getchar() at the end of the program code. In fact, this is a command under DOS.
Example:

#include "stdio.h"
int main()
{
    printf("hello world\n");
    system("pause");
}

The problem is that when you Press F5, the correct one should be Ctrl+F5, and the window will display Press any key to continue… That’s it. You can also see the results of the program run.
This is because F5 is in Debugging mode, where the window does not remain open once the application finishes running. If CTRL +F5 is in Start Without Debugging mode, you’ll be able to see the results.
 
If you press Ctrl+F5 and it still flashes, then use the following Settings:
In the top navigation bar, click “Project” –>; “Properties” – & gt;” Configure property “–>” The linker – & gt; “” System – & gt; “” Subsystems (there is a drop-down icon to the right of the window) “–>; SUBSYSTEM:CONSOLE The drop down box selects’ /SUBSYSTEM:CONSOLE ‘– gt; Finally “confirm” –>; Click on the top right corner “file “–>; “Save it all.”
 
// Finally, press Ctrl + F5 to avoid the flashback problem.
    

The reason of OpenGL configuration error in VS

When working with OpenGL, I encountered a number of errors:
The glut32.lib library cannot be opened.
2. Openg. DLL file missing
And so on.
After my debugging, I found two possible reasons. Please pay attention when debugging, it may be caused by these two reasons.
1.VS has two development platforms, X64 and Win32, I found that there are problems on X64 platform, first, there is no such error on Win32 platform, I guess it is because OpenGL is 32-bit.
I don’t know if OpenGL 64 is going to work, but I didn’t verify it, but you can verify it.
2. If there is an error in question 2, it may be that the lib library file in connector input is incorrect. I have tested it, and if it is changed to glu32.lib and glut32.lib, the error can be eliminated!
This is the problem I encountered in writing OpenGL, to give you a debugging idea.