在OpenGL中怎样安装glut库

 Visual C++用户:
1。下载GLUT库:http://www.opengl.org/resources/libraries/glut/glutdlls37beta.zip
2。将压缩包内的glut.h放到.../Microsoft Visual Studio/VC98/Include/GL目录下
   将glut32.lib放到.../Microsoft Visual Studio/VC98/Lib目录下
   将glut32.dll放到X:/windows/systom32目录下(win98用户放到X:/windows/systom目录下)
3。建立一个控制台工程Win32 Console Application,加入hello.c并运行:
#include <GL/glut.h>

void display(void)
{
   glClear (GL_COLOR_BUFFER_BIT);/* clear all pixels  */
   glColor3f (1.0, 1.0, 1.0);
   glBegin(GL_POLYGON);/* draw white polygon with corners at(0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)*/
      glVertex3f (0.25, 0.25, 0.0);
      glVertex3f (0.75, 0.25, 0.0);
      glVertex3f (0.75, 0.75, 0.0);
      glVertex3f (0.25, 0.75, 0.0);
   glEnd();
   glFlush ();/* start processing buffered OpenGL routines  */
}

void init (void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);/* select clearing color  */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/* initialize viewing values  */
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);/*Declare initial display mode(single buffer and RGBA).*/
   glutInitWindowSize (250, 250); /*Declare initial window size.*/
   glutInitWindowPosition (100, 100);/*Declare initial window position.*/
   glutCreateWindow ("hello");/*Open window with "hello"in its title bar.*/ 
   init ();/*Call initialization routines.*/
   glutDisplayFunc(display); /*Register callback function to display graphics.*/
   glutMainLoop();/*Enter main loop and process events.*/
   return 0;   /* ANSI C requires main to return int. */
}

DEVCPP用户:
1。下载GLUT库:http://www.cs.uofs.edu/~mpc3/cmps370/glut-MingW-DEV-C++.zip
2。将压缩包内的glut.h放到.../Dev-Cpp/include/GL目录下
   将libglut.a和glut32.def放到.../Dev-Cpp/lib目录下
   将glut32.dll放到X:/windows/systom32目录下(win98用户放到X:/windows/systom目录下)
3。建立一个控制台工程Console Application,修改工程属性project options中的参数parameter中的连接器linker,加入库或者对象addlibrary or object中加入:
.../Dev-Cpp/lib/libglu32.a
.../Dev-Cpp/lib/libglut32.a
.../Dev-Cpp/lib/libopengl32.a
或直接键入-lopengl32 -lglu32 -lglut32


4。加入hello.c并运行:
#include <GL/glut.h>

void display(void)
{
   glClear (GL_COLOR_BUFFER_BIT);/* clear all pixels  */
   glColor3f (1.0, 1.0, 1.0);
   glBegin(GL_POLYGON);/* draw white polygon with corners at(0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)*/
      glVertex3f (0.25, 0.25, 0.0);
      glVertex3f (0.75, 0.25, 0.0);
      glVertex3f (0.75, 0.75, 0.0);
      glVertex3f (0.25, 0.75, 0.0);
   glEnd();
   glFlush ();/* start processing buffered OpenGL routines  */
}

void init (void)
{
   glClearColor (0.0, 0.0, 0.0, 0.0);/* select clearing color  */
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/* initialize viewing values  */
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);/*Declare initial display mode(single buffer and RGBA).*/
   glutInitWindowSize (250, 250); /*Declare initial window size.*/
   glutInitWindowPosition (100, 100);/*Declare initial window position.*/
   glutCreateWindow ("hello");/*Open window with "hello"in its title bar.*/ 
   init ();/*Call initialization routines.*/
   glutDisplayFunc(display); /*Register callback function to display graphics.*/
   glutMainLoop();/*Enter main loop and process events.*/
   return 0;   /* ANSI C requires main to return int. */
}


for JAVAer:
如果你是JAVA程序员,我向你推荐JOGL,JOGL项目是目前流行的OpenGL的JAVA绑定,它的官方主页是https://jogl.dev.java.net
当前的JOGL支持OpenGL 1.5,和绝大多数的扩展,当然如果你是OpenGL高手,你会知道,只要显卡驱动支持,我们一样可以调用JOGL没有提供的OpenGL扩展函数。
好吧,假定你有一个JAVA的编译环境,你的JAVA SDK版本在1.42以上,(你可以netbeans.org下载到免费的netbeans编译器)


安装步骤:
1。在https://jogl.dev.java.net的Precompiled binaries and documentation的Release Builds 2004的1.1b07 - November 19目录
   下载jogl.jar和jogl-natives-win32.jar(不是windows用户的话,下载jogl-natives-myos.jar)
2。将jogl.jar安装到CLASSPATH
3。运行下面程序,得到java.library.path
public class try {
   public static void main(String[] args)
   {
System.out.println(System.getProperty("java.library.path"));

}
4。解压缩jogl-natives-win32.jar,将jogl.dll和joglcg.dll放到任意的java.library.path目录中
5。运行看下面的程序,它能跑就说明安装好了
public class zaishishi {
    public static void main(String[] args)
    {
        System.loadLibrary("jogl" );
    }
}
6。运行我们的例子hello.java
import net.java.games.jogl.*;
 
import java.awt.*;
import java.awt.event.*;
 
public class hello
{
    public static void main( String[] args )
    {
        try
        {
            Frame Frame = new Frame("hello"); /*Open window with "hello"in its title bar.*/
            Frame.setSize(250,250); /*Declare initial window size.*/
 
            GLCapabilities glCaps = new GLCapabilities();
 
            GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas( glCaps );
            canvas.addGLEventListener(new Renderer());
            Frame.add( canvas );
 
            final Animator animator = new Animator( canvas);
            Frame.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    animator.stop();
                    System.exit(0);
                }
              });
        Frame.show();
        animator.start();
        }
        catch( Exception e )
        {
            e.printStackTrace();
        }
    }
}
class Renderer implements GLEventListener
{
    private GL              gl;
    private GLDrawable      glDrawable;
 
    public void init(GLDrawable drawable)
    {
        this.gl = drawable.getGL();
        this.glDrawable = drawable;
        drawable.setGL( new DebugGL(drawable.getGL() ));
     gl.glClearColor (0.0f, 0.0f, 0.0f, 0.0f);/* select clearing color  */
     gl.glMatrixMode(GL.GL_PROJECTION);
     gl.glLoadIdentity();
     gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);/* initialize viewing values  */
    }
 
    public void display(GLDrawable drawable)
    {
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);/* clear all pixels  */
        gl.glLoadIdentity();
        gl.glColor3f(1.0f, 1.0f, 1.0f );
        gl.glBegin( GL.GL_POLYGON); /* draw white polygon with corners at(0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)*/
        gl.glVertex3f (0.25f, 0.25f, 0.0f);
        gl.glVertex3f (0.75f, 0.25f, 0.0f);
        gl.glVertex3f (0.75f, 0.75f, 0.0f);
        gl.glVertex3f (0.25f, 0.75f, 0.0f);
        gl.glEnd();
 gl.glFlush();/* start processing buffered OpenGL routines  */
    }
 
    public void reshape(GLDrawable drawable, int x, int y, int width, int height)
    {
    }
 
    public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged)
    {
    }
 
}

 

你可能感兴趣的:(application,buffer,processing,callback,documentation,initialization)