opengl 使用简介

Click here to load reader

Upload: chin

Post on 14-Jan-2016

97 views

Category:

Documents


3 download

DESCRIPTION

OpenGL 使用简介. 简介. OpenGL ( Open Graphics Library )是个定义了一个跨编程语言、跨平台的编程接口的规格,是个专业的 3D 程序接口,是一个功能强大,调用方便的底层 3D 图形库。 OpenGL 是个与硬件无关的软件接口,可以在不同的平台如 Windows 95 、 Windows NT 、 Unix 、 Linux 、 MacOS 、 OS / 2 之间进行移植。 - PowerPoint PPT Presentation

TRANSCRIPT

  • OpenGL

  • OpenGLOpen Graphics Library3D3DOpenGLWindows 95Windows NTUnixLinuxMacOSOS2 Microsoft WindowsDirect3DOpenGLCAD

  • OpenGLSGIIRIS GL19927SGIOpenGL1.0OpenGL2.01.51.41.31.21.1or 1.0200683OpenGL version 2.1 OpenGL1992OpenGLARBARBAPIOpenGL20026ARB3DlabsApple ComputerATI TechnologiesDell ComputerEvans & SutherlandHewlett-PackardIBMIntelMatrox NVIDIASGISun Microsystems Microsoft20033

  • GL1OpenGL32Windows WindowsNTWindows95 OpenGL32.DLLGlu32.DLL\WINDOWS\system32window2000OPENGL32.DLLglu32.dllVC6VS.NETGLVC6\Microsoft Visual Studio\VC98\Include\GLVS.NET.2005\Microsoft Visual Studio 8\VC\PlatformSDK\Include\glGl.hGlaux.hGlu.hLibOpenGL32.libGLu32.libGLaux.libVC#include // Header File For The OpenGL32 Library#include // Header File For The GLu32 Library#include // Header File For The Glaux Library

  • GL2OpenGLOSOpenGLOpen InventorCosmo3DOptimizer

  • OpenGL

  • OpenGLglOpenGLgluXOpenGLglXvoid glBegin(GLenum mode);void gluBeginCurve(GLUnurbs* nurb);void glXFreeContextEXT(Display * dpy, GLXContext ctx);GL_POINTS,GL_LINES,GL_LINE_STRIP,GL_LINE_LOOP,GL_TRIANGLES,GL_TRIANGLE_STRIP,GL_TRIAN,GL_QUADS,GL_QUAD_STRIP

  • void glVertex3s(GLshort x, GLshort y, GLshort z);void glVertex3i(GLint x, GLint y, GLint z);void glVertex3f(GLfloat x, GLfloat y, GLfloat z);void glVertex3d(GLdouble x, GLdouble y, GLdouble z);

  • Visual C/C++ 6.0Visual C/C++: Console () Win32: , OpenGL Win32 Windows GLUT . : Project -> settings Link Category Output Entry-point synmbol mainCRTStartup, Win32: Project options subsystem:windows subsystem:console : // #pragma comment( linker,"/subsystem:\"windows\"/entry:\"mainCRTStartup\"" )

  • GLUTlink#include #include #include ProjectSettings Settings Link Libraries OpenGLopengl32.lib glu32.lib glaux.lib

  • GLUTGLUT ( OpenGL Utility Toolkit ) windows C/C++ GLUT , : GLUT.H - GL GLUT.LIB (SGI windows) glut32.lib () - , LIB glut32.dll (Windows) glut.dll (SGI Windows) - OpenGL glut32.dllDLLwindow XPVC6GLUTglutdllsglut32.dllglut.dll\windows\system32glut.h...\Microsoft Visual Studio\VC98\Include\GLglut32.libglut.lib\Microsoft Visual Studio\VC98\Lib

  • #include

    void renderScene(void) { // glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex3f(-0.5,-0.5,0.0); glVertex3f(0.5,0.0,0.0); glVertex3f(0.0,0.5,0.0); glEnd(); glFlush(); }

    void main(int argc, char **argv) { glutInit(&argc, argv); //glutglutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA); //glutInitWindowPosition(100,100); //glutInitWindowSize(320,320); //glutCreateWindow(3D Tech- GLUT Tutorial); //titleglutDisplayFunc(renderScene);//renderScene glutMainLoop(); //}

  • void glutReshapeFunc(void (*func)(int width, int height)); void glutIdleFunc(void (*func)(void)); funcwindowmousekeyboardmenusub windowfontglut

  • #includefloat angle = 0.0;void changeSize(int w, int h) {if(h == 0)h = 1;float ratio = 1.0* w / h;glMatrixMode(GL_PROJECTION);glLoadIdentity();glViewport(0, 0, w, h);gluPerspective(45,ratio,1,1000);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(0.0,0.0,5.0, 0.0,0.0,-1.0, 0.0f,1.0f,0.0f);}

    void renderScene(void) {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushMatrix();glRotatef(angle,0.0,1.0,0.0);glBegin(GL_TRIANGLES);glVertex3f(-0.5,-0.5,0.0);glVertex3f(0.5,0.0,0.0);glVertex3f(0.0,0.5,0.0);glEnd();glPopMatrix();angle++;glutSwapBuffers();}

  • void main(int argc, char **argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); //, // glutInitWindowPosition(100,100);glutInitWindowSize(320,320);glutCreateWindow("Lighthouse 3D - GLUT Tutorial");glutDisplayFunc(renderScene);glutIdleFunc(renderScene);//register a callback function to be called when the application is idle glutReshapeFunc(changeSize);//Preparing the window for a reshapeglutMainLoop();}

  • webOpenGL http://www.opengl.orgOpenGL 2.1 Referencehttp://www.opengl.org/sdk/docs/manGLUThttp://www.opengl.org/resources/libraries/glut/NEHEGLhttp://nehe.gamedev.net

    specification The OpenGL Utility Toolkit (GLUT) Programming Interface (PDF)OpenGL 2.1 specification (PDF)

    bookOpenGLOpenGLOpenGL Shading Language