GLUT Tutorial : Setup

来源:互联网 发布:淘宝数据管理系统 编辑:程序博客网 时间:2024/05/05 19:30

下面的一些文档转载自http://www.lighthouse3d.com/opengl/tutorials.shtml 感觉不错,贴出来,做个储备吧

GLUT stands for OpenGL Utility Toolkit. Mark J. Kilgard, to enable the construction of OpenGL applications that are truly window system independent, conceived the GLUT library. Thanks to GLUT, we can write applications without having to learn about X windows or Microsoft's own window system. Kilgard implemented the version for X windows, and later Nate Robins ported it to Microsoft Windows. Thanks to both, you did a great job.

 

In this tutorial I'll introduce you to the basics of building an application using GLUT. This tutorial won't introduce fancy visual effects in order to keep the code as simple as possible.

 

What you need

 

In order to write applications with GLUT you should have the latest version (at the time of writing this, I believe it is 3.7). The GLUT distribution comes with lots and lots of examples so after you read through the basics in here you'll have plenty of material to go on. Check out the GLUTs page.

 

In order to write a C application using GLUT you'll need three files:

  • glut.h - This is the file you'll have to include in your source code. The common place to put this file is in the gl folder which should be inside the include folder of your system.
  • glut.lib (SGI version for Windows) and glut32.lib (Microsoft's version) - This file must be linked to your application so make sure to put it your lib folder.
  • glut32.dll (Windows) and glut.dll (SGI version for Windows) - choose one according to the OpenGL you're using. If using Microsoft's version then you must choose glut32.dll. You should place the dll file in your system folder.
  •  

    Setting up in Visual C/C++ 6.0

     

    There are two options available for a project in Visual C/C++: console, and Win32. the first is the most common option. The application will have two windows: a console window and the OpenGL window. With Win32 it is still possible to build an application using GLUT without messing up with windows programming. All you have to do is to change one setting.

  • Select project->settings from the main menu;
  • Select the "Link" tab from the dialog box;
  • Select "Output" from the "Category" combo box;
  • In the "Entry-point symbol" textbox type "mainCRTStartup"
  • For an existing console project there is a simple way to transform it into a Win32 application, i.e. to get rid of the console window.

  • Follow the steps above to add the entry-point symbol
  • In the "Project options" textbox replace "subsystem:console" with "subsystem:windows"
  • Alternatively just add the following line to the beginning of your c code:


        // #pragma comment( linker, "/subsystem:/"windows/" /entry:/"mainCRTStartup/"" )  


    Note that the line is commented on purpose.

     

    And thats all there is to it, now the application has no console window, just the OpenGL window. In Visual C/C++ you'll have to do the following in order to link an application using GLUT:

  • Select Project/Settings from the main menu.
  • A dialog box appears, select the Link tab.
  • Add the following files to the Object/library modules: opengl32.lib glut32.lib glu32.lib
  • Note: I've added glu32.lib and opengl32.lib as well. These are the two libraries for the standard OpenGL. GLU is an API that comes with the standard OpenGL distribution.

     

    OK, so all is set, lets learn how to write GLUT applications. If there is anything that is not quite clear please let me know and I'll try to improve it. Your feedback is important.

     

    I hope you enjoy this tutorial.

     

    Antonio