我要发帖 回复

正式会员

6

主题

44

积分

0

专家分

:

私信
发表时间 : 2008-7-29 11:31:36 | 浏览 : 1852    评论 : 6
代码如下:/*
* Copyright (c) 1993-2003, Silicon Graphics, Inc.
* All Rights Reserved
*
* Permission to use, copy, modify, and distribute this software for any
* purpose and without fee is hereby granted, provided that the above
* copyright notice appear in all copies and that both the copyright
* notice and this permission notice appear in supporting documentation,
* and that the name of Silicon Graphics, Inc. not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
* THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
* WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
* FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
* GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
* SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF
* PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD
* PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN ADVISED OF
* THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE
* OR PERFORMANCE OF THIS SOFTWARE.
*
* US Government Users Restricted Rights
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
* (c)(1)(ii) of the Rights in Technical Data and Computer Software
* clause at DFARS 252.227-7013 and/or in similar or successor clauses
* in the FAR or the DOD or NASA FAR Supplement.  Unpublished - rights
* reserved under the copyright laws of the United States.
*
* Contractor/manufacturer is:
*        Silicon Graphics, Inc.
*        1500 Crittenden Lane
*        Mountain View, CA  94043
*        United State of America
*
* OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
*/

/*
*  font.c
*
*  Draws some text in a bitmapped font.  Uses glBitmap()
*  and other pixel routines.  Also demonstrates use of
*  display lists.
*/
#include <GL/glut.h>
#include <stdlib.h>
#include <string.h>

GLubyte space[] =
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

GLubyte letters[][13] = {
{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0x66, 0x3c, 0x18},
{0x00, 0x00, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe, 0xc7, 0xc3, 0xc3, 0xc7, 0xfe},
{0x00, 0x00, 0x7e, 0xe7, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
{0x00, 0x00, 0xfc, 0xce, 0xc7, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xc7, 0xce, 0xfc},
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xc0, 0xff},
{0x00, 0x00, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0xfc, 0xc0, 0xc0, 0xc0, 0xff},
{0x00, 0x00, 0x7e, 0xe7, 0xc3, 0xc3, 0xcf, 0xc0, 0xc0, 0xc0, 0xc0, 0xe7, 0x7e},
{0x00, 0x00, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3, 0xff, 0xc3, 0xc3, 0xc3, 0xc3, 0xc3},
{0x00, 0x00, 0x7e, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x7e},
{0x00, 0x00, 0x7c, 0xee, 0xc6, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06},
{0x00, 0x00, 0xc3, 0xc6, 0xcc, 0xd8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x00, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3c, 0x3c, 0x66, 0x66, 0xc3},
{0x00, 0x00, 0xff, 0xc0, 0xc0, 0x60, 0x30, 0x7e, 0x0c, 0x06, 0x03, 0x03, 0xff}
};

GLuint fontOffset;

void makeRasterFont(void)
{
   GLuint i, j;
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

   fontOffset = glGenLists (128);
   for (i = 0,j = 'A'; i < 26; i++,j++) {
      glNewList(fontOffset + j, GL_COMPILE);
      glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, letters);
      glEndList();
   }
   glNewList(fontOffset + ' ', GL_COMPILE);
   glBitmap(8, 13, 0.0, 2.0, 10.0, 0.0, space);
   glEndList();
}

void init(void)
{
   glShadeModel (GL_FLAT);
   makeRasterFont();
}

void printString(char *s)
{
   glPushAttrib (GL_LIST_BIT);
   glListBase(fontOffset);
   glCallLists(strlen(s), GL_UNSIGNED_BYTE, (GLubyte *) s);
   glPopAttrib ();
}

/* Everything above this line could be in a library
* that defines a font.  To make it work, you've got
* to call makeRasterFont() before you start making
* calls to printString().
*/
void display(void)
{
   GLfloat white[3] = { 1.0, 1.0, 1.0 };

   glClear(GL_COLOR_BUFFER_BIT);
   glColor3fv(white);

   glRasterPos2i(20, 60);
   printString("THE QUICK BROWN FOX JUMPS");
   glRasterPos2i(20, 40);
   printString("OVER A LAZY DOG");
   glFlush ();
}

void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   glOrtho (0.0, w, 0.0, h, -1.0, 1.0);
   glMatrixMode(GL_MODELVIEW);
}

void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0);
   }
}

/*  Main Loop
*  Open window with initial window size, title bar,
*  RGBA display mode, and handle input events.
*/
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize(300, 100);
   glutInitWindowPosition (100, 100);
   glutCreateWindow(argv[0]);
   init();
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutDisplayFunc(display);
   glutMainLoop();
   return 0;
}
这是其中的一个font.c
我已经将glut.lib,glut32.lib放到了vc98\lib下,将glut.h放到了include\gl下,将glut.dll,glut32.dll放到了system32下,然后建了一个win32控制台空工程,在工程\设置\链接下也将opengl32.lib,glu32.lib,glaux.lib,glut.lib,glut32.lib加入了,网上说这样编译都可以,可是我编译时出现了如下错误:
Compiling...
font.c
Linking...
font.obj : error LNK2001: unresolved external symbol ___glutInitWithExit@12
font.obj : error LNK2001: unresolved external symbol ___glutCreateWindowWithExit@8
Debug/wwwww.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.

wwwww.exe - 1 error(s), 0 warning(s)
请大家帮忙看看
谢谢!

最近VR访客

tttss 评论于2008-7-29 13:21:03
glut的版本冲突造成的
把glut.lib从link中去了,只留glut32.lib
G-Willson 评论于2008-7-29 15:25:28

还是出错

我按照你说的把glut.lib去掉了,还是出现同样的错误。谢谢你的回答
tttss 评论于2008-7-29 16:57:43
我编译了,没问题.
1.jpg
G-Willson 评论于2008-7-30 09:58:00

为什么还不可以啊?

我又重新作了好几遍,换了电脑试了好几遍,还是同样的问题。还有没有其他的原因能导致这样的问题啊?比如说glut版本的问题,vc++的配置问题等
tttss 评论于2008-7-30 12:43:58
我用的Glut,你试一下

glut.rar

87.64 KB, 下载次数: 1

评分

参与人数 1积分 +10 收起 理由
tan_dunming + 10 热心回答问题

查看全部评分

G-Willson 评论于2008-7-30 16:19:20

问题已解决

我用了你的glut包试了试还是不行,我就上网百度,我觉得设置没有问题,就是glut版本的问题了,百度也说有可能是glut版本的问题。我从网上又下了个,结果成功了。通过这个问题收获挺大!
  还要特别感谢tttss 的耐心回答!!Thank you!
  这是我下的glut包

glut-3.7.6-bin.zip

117.09 KB, 下载次数: 75

手机版|VR开发网 ( 津ICP备18009691号 ) 统计 网安备12019202000257

GMT+8, 2020-1-28 02:28 AM

返回顶部