Visual Studio OpenGL configuration method
The files in the OpenGL Development Library include:
Dynamic Link Library file (. dll)
Glu32.dll, Glu. dll, glut. dll, and OpenGL. dll.
Header file (. h)
Gl. H, Glaux. H, glext. H, Glu. H, glut. H, and wglext. h.
Library file (. Lib)
Glaux. Lib, glu32.lib, Glu. Lib, glu32.lib, glut. Lib, opengl32.lib, and OpenGL. Lib.
Configuration method:
1. Copy the. h file in the Development Library to the \ include \ GL directory of Visual C ++ 6.0.
2. Copy the. Lib file to the \ lib directory of Visual C ++ 6.0.
3. Copy the. dll file to the System32 directory of the operating system.
CodeExample:
/* <Br/> name: glsample <br/> author: Blaine Hodge <br/> Description: OpenGL sample. read the fileinclude \ GL \ readme.txt <br/> for informations on usingopengl. <br/> date:-<br/> copyright: public domain <br/> */</P> <p> // des </P> <p> # include <windows. h> <br/> # include <Gl/GL. h> </P> <p> # pragma comment (Lib, "opengl32.lib") <br/> # pragma comment (Lib, "OpenGL. lib ") <br/> # pragma comment (Lib," glu32.lib ") <Br/> # pragma comment (Lib, "glu32.lib") <br/> # pragma comment (Lib, "Glaux. lib ") <br/> # pragma comment (Lib," Glu. lib ") </P> <p> // function declarations </P> <p> lresult callback <br/> wndproc (hwnd, uint message, wparam, lparam); <br/> voidenableopengl (hwnd, HDC * HDC, hglrc * HRC); <br/> voiddisableopengl (hwnd, HDC, hglrc HRC ); </P> <p> // winmain </P> <p> int winapi winmain (hinstanc E hinstance, hinstancehprevinstance, <br/> lpstr lpcmdline, int icmdshow) <br/>{< br/> wndclass WC; <br/> hwnd; <br/> HDC; <br/> hglrc HRC; <br/> MSG; <br/> bool bquit = false; <br/> float Theta = 0.0f; </P> <p> // register windowclass <br/> WC. style = cs_owndc; <br/> WC. lpfnwndproc = wndproc; <br/> WC. cbclsextra = 0; <br/> WC. cbwndextra = 0; <br/> WC. hinstance = hinstance; <br/> WC. hico N = loadicon (null, idi_application); <br/> WC. hcursor = loadcursor (null, idc_arrow); <br/> WC. hbrbackground = (hbrush) getstockobject (black_brush); <br/> WC. lpszmenuname = NULL; <br/> WC. lpszclassname = "glsample"; <br/> registerclass (& WC ); </P> <p> // create mainwindow <br/> hwnd = createwindow (<br/> "glsample", "OpenGL sample ", <br/> ws_caption | ws_popupwindow | ws_visible, <br/> 0, 0,256, 256, <br/> null, null, hinstance, null); </P> <p> // enable openglfor the window <br/> enableopengl (hwnd, & HDC, & HRC); </P> <p> // program mainloop <br/> while (! Bquit) <br/>{< br/> // check formessages <br/> If (peekmessage (& MSG, null, 0, 0, pm_remove )) <br/>{< br/> // handleor dispatch messages <br/> If (MSG. message = wm_quit) <br/>{< br/> bquit = true; <br/>}< br/> else <br/>{< br/> translatemessage (& MSG); <br/> dispatchmessage (& MSG ); <br/>}</P> <p >}< br/> else <br/>{< br/> // openglanimation code goes here </P> <p> glclearcolor (0.0f, 0.0f, 0.0f, 0.0f); <br/> glclear (gl_color_buffer_bit); </P> <p> glpushmatrix (); <br/> glrotatef (Theta, 0.0f, 0.0f, 1.0f); <br/> glbegin (gl_triangles); <br/> glcolor3f (1.0f, 0.0f, 0.0f); glvertex2f (0.0f, 1.0f); <br/> glcolor3f (0.0f, 1.0f, 0.0f); glvertex2f (0.87f,-0.5f); <br/> glcolor3f (0.0f, 0.0f, 1.0f); glvertex2f (-0.87f,-0.5f ); <br/> glend (); <br/> glpopmatrix (); <br/> swapbuffers (HDC); </P> <p> Theta + = 1.0f; </P> <p >}< br/> // shutdown OpenGL <br/> disableopengl (hwnd, HDC, HRC ); <br/> // destroy thewindow explicitly <br/> destroywindow (hwnd); <br/> returnmsg. wparam; <br/>}</P> <p> // window procedure </P> <p> lresult callbackwndproc (hwnd, uint message, wparam, lparam) <br/>{< br/> switch (Message) <br/>{< br/> casewm_create: <br/> return0; </P> <p> casewm_close: <br/> postquitmessage (0); <br/> return0; </P> <p> casewm_destroy: <br/> return0; </P> <p> casewm_keydown: <br/> switch (wparam) <br/> {<br/> casevk_escape: <br/> postquitmessage (0); <br/> return0; <br/>}< br/> return0; </P> <p> default: <br/> returndefwindowproc (hwnd, message, wparam, lparam ); <br/>}</P> <p> // enable OpenGL </P> <p> void enableopengl (hwnd, HDC * HDC, hglrc * HRC) <br/>{< br/> pixelformatdescriptor PFD; <br/> int iformat; </P> <p> // get the devicecontext (DC) <br/> * HDC = getdc (hwnd); </P> <p> // set the pixelformat for the DC <br/> zeromemory (& PFD, sizeof (PFD); <br/> PFD. nsize = sizeof (PFD); <br/> PFD. nversion = 1; <br/> PFD. dwflags = pfd_draw_to_window | <br/> pfd_support_opengl | pfd_doublebuffer; <br/> PFD. ipixeltype = pfd_type_rgba; <br/> PFD. ccolorbits = 24; <br/> PFD. cdepthbits = 16; <br/> PFD. ilayertype = pfd_main_plane; <br/> iformat = choosepixelformat (* HDC, & PFD); <br/> setpixelformat (* HDC, iformat, & PFD ); </P> <p> // create andenable the render context (RC) <br/> * HRC = wglcreatecontext (* HDC); <br/> wglmakecurrent (* HDC, * HRC); <br/>}</P> <p> // disable OpenGL </P> <p> void disableopengl (hwnd, HDC, hglrc HRC) <br/>{< br/> wglmakecurrent (null, null); <br/> wgldeletecontext (HRC); <br/> releasedc (hwnd, HDC ); <br/>}
Note:
Forgot
# Pragmacomment (Lib, "XXX. lib ")
A link error occurs!