Error reason: missing reference
Solution: include & lt; algorithm & gt;
Error reason: missing reference
Solution: include & lt; algorithm & gt;
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
p>
p>
p>
p>
stdlib.h> , in return 0; Before adding system (” pause “); Let it press any will continue.
C/C++ library function (tolower/toupper) implements case conversion of letters
This article will introduce the library function to implement the case conversion of letters, commonly used in the type. H (c ++ is cctype) library file under the definition of function methods. First let’s look at the prototype implementation of the tolower/toupper function under C:
int tolower(int c)
{
if ((c >= 'A') && (c <= 'Z'))
return c + ('a' - 'A');
return c;
}
int toupper(int c)
{
if ((c >= 'a') && (c <= 'z'))
return c + ('A' - 'a');
return c;
}
And I’m going to do that with two little demos.
C implementation:
#include<string.h> //strlen
#include<stdio.h> //printf
#include<ctype.h> //tolower
int main()
{
int i;
char string[] = "THIS IS A STRING";
printf("%s\n", string);
for (i = 0; i < strlen(string); i++)
{
string[i] = tolower(string[i]);
}
printf("%s\n", string);
printf("\n");
}
Save as xxX. c file, execute: GCC-O XXX xxX. c generate execute file XXX. Operation:./ XXX
above is the implementation of C. Similarly, the implementation under C++ is as follows:
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string str= "THIS IS A STRING";
for (int i=0; i <str.size(); i++)
str[i] = tolower(str[i]);
cout<<str<<endl;
return 0;
}
Save as xxx. CPP, execute g++ xxx. CPP to generate the execution file a.ut, execute a.ut, and the effect is as follows:
The demo above
implements the upper case tolower case conversion, again, the lower case toupper case conversion is the same, just replace tolower with toupper.