VC6 Download
http://blog.csdn.net/bcbobo21cn/article/details/44200205
Demoproject and Glut Library downloads
Http://pan.baidu.com/s/1pLSpKiZ
One environment configuration
References
http://blog.itpub.net/17267437/viewspace-545635/
Unzip the GLUT library
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
Copy Glut.h to For example the following folder;
Copy the two lib of Figure 1 into the following folder, for example.
Copy the two DLLs in Figure 1 to such folders as the following (even 64-bit systems).
Project Settings join four Lib
Two examples 1
#include <GL/glut.h>
#include <math.h>
const int n = 200;
Const Glfloat R = 0.5f;
Const Glfloat Pi = 3.1415926536f;
void Mydisplay (void)
{
int i;
Draw a green Square
Glclear (Gl_color_buffer_bit);
glcolor3f (0.0f,1.0f,0.0f);
GLRECTF ( -0.5f, 0.4f, 0.0f, 0.9f); Draw a green square.
Glflush ();
Glclearcolor (0.0,0.0,0.0,0.0);
Glclear (Gl_color_buffer_bit);
glcolor4f (1.0,0.0,0.0,1.0); Set the quad color
Glbegin (gl_quads);
glvertex3f ( -0.2,-0.2,0.0);
glvertex3f (0.2,-0.2,0.0);
glvertex3f (0.2,0.2,0.0);
glvertex3f ( -0.2,0.2,0.0);
Glend ();
glcolor4f (1.0,0.0,0.0,1.0); Set the point color
Glpointsize (10);
Glbegin (gl_points);
glvertex3f ( -0.5,-0.5,0.0);
glvertex3f (0.5,-0.5,0.0);
glvertex3f (0.5,0.5,0.0);
glvertex3f ( -0.5,0.5,0.0);
Glend ();
glcolor4f (1.0,0.0,0.0,1.0); Set the line Color
Gllinewidth (5);
Glbegin (Gl_lines);
glvertex3f ( -0.5,-0.5,0.0);
glvertex3f (0.5,-0.5,0.0);
glvertex3f (0.5,0.5,0.0);
glvertex3f ( -0.5,0.5,0.0);
Glend ();
/*glbegin (Gl_polygon);
for (i=0; i<n; ++i)
GLVERTEX2F (R*cos (2*pi/n*i), R*sin (2*pi/n*i));
Glend (); */
Glflush ();
}
int main (int argc, char *argv[])
{
Glutinit (&ARGC, argv);
Glutinitdisplaymode (Glut_rgb | Glut_single);
Glutinitwindowposition (100, 0);
Glutinitwindowsize (1024, 768);
Glutcreatewindow ("OpenGL basic Drawing");
Glutdisplayfunc (&mydisplay);
Glutmainloop ();
return 0;
}
Online said to change the _console, I did not change can also be implemented in the development environment.
Three Examples 2
#include <GL/glut.h>
void Mydisplay (void)
{
Glclear (Gl_color_buffer_bit);
GLRECTF ( -0.5f, -0.5f, 0.5f, 0.5f);
Glflush ();
}
int main (int argc, char *argv[])
{
Glutinit (&ARGC, argv);
Glutinitdisplaymode (Glut_rgb | Glut_single);
Glutinitwindowposition (100, 100);
Glutinitwindowsize (400, 400);
Glutcreatewindow ("First OpenGL program");
Glutdisplayfunc (&mydisplay);
Glutmainloop ();
return 0;
}
Four examples 3
#include <GL/glut.h>
Called to draw scene
void Rendersence (void)
{
Clear the window with current clearing color
Glclear (Gl_color_buffer_bit);
Flush Drawing Commands
Glflush ();
}
Set up the rendering state
void Setuprc (void)
{
Glclearcolor (0.0f,0.0f,1.0f,1.0f); The background color is blue at this time
}
int main (int argc, char *argv[])
{
Glutinit (&ARGC, argv);
Glutinitdisplaymode (glut_single| glut_single| GLUT_RGB);
Glutcreatewindow ("simple"); The form is named "Simple"
Glutdisplayfunc (rendersence);
SETUPRC ();
Glutmainloop ();
return 0;
}
Compile, there are a bunch of errors below;
Demo4.cpp
Y:\dddd10\vc6opengldemo\demo4\demo4.cpp (5): Error c2018:unknown character ' 0xa1 '
Y:\dddd10\vc6opengldemo\demo4\demo4.cpp (5): Error c2018:unknown character ' 0xa1 '
Y:\dddd10\vc6opengldemo\demo4\demo4.cpp (): Error c2018:unknown character ' 0xa1 '
......
is due to the inclusion of full-width characters in the code, finding that the full-width character is a space, replacing the full-width space with a half-width space and then compiling it;
Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /center ">
Five Examples 4
#include <GL/glut.h>
void background (void)
{
Glclearcolor (0.0,0.0,0.0,0.0);//Set the background color to black
}
void Mydisplay (void)
{
Glclear (gl_color_buffer_bit);//buffer set to Color writable
Glbegin (gl_triangles);//Start drawing triangles
Glshademodel (Gl_smooth);//set to smooth shading mode
glcolor3f (1.0,0.0,0.0);//Set the first vertex to be red
GLVERTEX2F ( -1.0,-1.0);//Set the coordinates of the first vertex to ( -1.0,-1.0)
glcolor3f (0.0,1.0,0.0);//Set a second vertex to be green
GLVERTEX2F (0.0,-1.0);//Set the coordinates of the second vertex to (0.0,-1.0)
glcolor3f (0.0,0.0,1.0);//Set a third vertex to be blue
GLVERTEX2F ( -0.5,1.0);//sets the coordinates of the third vertex to (-0.5). 1.0)
Glend ();//triangle End
Glflush ();//forcing OpenGL functions to execute in a limited time
}
void Myreshape (Glsizei w,glsizei h)
{
Glviewport (0,0,w,h);//Set viewport
Glmatrixmode (gl_projection);//indicates that the current matrix is gl_projection
Glloadidentity ();//replace the current matrix with a unit array
if (w <= h)
Gluortho2d ( -1.0,1.5,-1.5,1.5* (glfloat) h/(glfloat) w);//define two-dimensional face projection matrix
Else
Gluortho2d ( -1.0,1.5* (glfloat) w/(glfloat) h,-1.5,1.5);
Glmatrixmode (Gl_modelview);//indicates that the current matrix is Gl_modelview
}
int main (int argc,char * * argv)
{
/* Initialize */
Glutinit (&ARGC,ARGV);
Glutinitdisplaymode (glut_single| GLUT_RGB);
Glutinitwindowsize (400,400);
Glutinitwindowposition (200,200);
/* Create form */
Glutcreatewindow ("Triangle");
/* Draw and display */
Background ();
Glutreshapefunc (Myreshape);
Glutdisplayfunc (Mydisplay);
Glutmainloop ();
return (0);
}
Six OpenGL Resource Links
Http://www.cnblogs.com/phinecos/category/90224.html
MFC-based OpenGL programming
Diagram VC + + OpenGL environment Configuration and several introductory examples