游戏开发论坛

 找回密码
 立即注册
搜索
查看: 3429|回复: 1

glTexImage3D函数为什么不能执行

[复制链接]

1

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2005-3-1 20:46:00 | 显示全部楼层 |阅读模式
这是完整出自红宝书的一个程序:

#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

#ifdef GL_VERSION_1_2
#define        iWidth 16
#define        iHeight 16
#define iDepth 16

static GLubyte image[iDepth][iHeight][iWidth][3];
static GLuint texName;

/*  Create a 16x16x16x3 array with different color values in
*  each array element [r, g, b].  Values range from 0 to 255.
*/

void makeImage(void)
{
         int s, t, r;
   
         for (s = 0; s < 16; s++)
                  for (t = 0; t < 16; t++)
                           for (r = 0; r < 16; r++) {
                                        image[r][t][0] = (GLubyte) (s * 17);
                                        image[r][t][1] = (GLubyte) (t * 17);
                                        image[r][t][2] = (GLubyte) (r * 17);
                           }
}

void init(void)
{   
         glClearColor (0.0, 0.0, 0.0, 0.0);
         glShadeModel(GL_FLAT);
         glEnable(GL_DEPTH_TEST);

         makeImage();
         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

         glGenTextures(1, &texName);
         glBindTexture(GL_TEXTURE_3D, texName);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER,
                                         GL_NEAREST);
         glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER,
                                         GL_NEAREST);
         glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, iWidth, iHeight,
                                  iDepth, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
         glEnable(GL_TEXTURE_3D);
}

void display(void)
{
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
         glBegin(GL_QUADS);
         glTexCoord3f(0.0, 0.0, 0.0); glVertex3f(-2.25, -1.0, 0.0);
         glTexCoord3f(0.0, 1.0, 0.0); glVertex3f(-2.25, 1.0, 0.0);
         glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(-0.25, 1.0, 0.0);
         glTexCoord3f(1.0, 0.0, 1.0); glVertex3f(-0.25, -1.0, 0.0);

         glTexCoord3f(0.0, 0.0, 1.0); glVertex3f(0.25, -1.0, 0.0);
         glTexCoord3f(0.0, 1.0, 1.0); glVertex3f(0.25, 1.0, 0.0);
         glTexCoord3f(1.0, 1.0, 0.0); glVertex3f(2.25, 1.0, 0.0);
         glTexCoord3f(1.0, 0.0, 0.0); glVertex3f(2.25, -1.0, 0.0);
         glEnd();
         glFlush();
}

void reshape(int w, int h)
{
         glViewport(0, 0, (GLsizei) w, (GLsizei) h);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
         glTranslatef(0.0, 0.0, -4.0);
}

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

int main(int argc, char** argv)
{
         glutInit(&argc, argv);
         glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
         glutInitWindowSize(250, 250);
         glutInitWindowPosition(100, 100);
         glutCreateWindow(argv[0]);
         init();
         glutReshapeFunc(reshape);
         glutDisplayFunc(display);
         glutKeyboardFunc (keyboard);
         glutMainLoop();
         return 0;
}
#else
int main(int argc, char** argv)
{
         fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0 or 1.1.\n");
         fprintf (stderr, "If your implementation of OpenGL has the right extensions,\n");
         fprintf (stderr, "you may be able to modify this program to make it run.\n");
         return 0;
}
#endif

编译的时候出现的错误提示:
f:\LC\My Documents\game\redbook\9-4 texture3d\texture3d.c(93): error C2220: 视为错误的警告,没有生成对象文件
f:\LC\My Documents\game\redbook\9-4 texture3d\texture3d.c(93): warning C4013: “glTexImage3D”未定义;假设外部返回 int

我不知道去哪里去找新的文件下载,似乎是应该找extension文件,可是这个函数并不是扩展函数呀,请指教,谢谢!

0

主题

1

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2005-3-3 10:30:00 | 显示全部楼层

Re: glTexImage3D函数为什么不能执行

编译的问题你自己解决
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//把下面这行代码加上,没有它,谁知道你用的是哪个纹理啊?
glBindTexture(GL_TEXTURE_3D, texName);
glBegin(GL_QUADS);
glTexCoord3f(0.0, 0.0, 0.0); glVertex3f(-2.25, -1.0, 0.0);
glTexCoord3f(0.0, 1.0, 0.0); glVertex3f(-2.25, 1.0, 0.0);
glTexCoord3f(1.0, 1.0, 1.0); glVertex3f(-0.25, 1.0, 0.0);
glTexCoord3f(1.0, 0.0, 1.0); glVertex3f(-0.25, -1.0, 0.0);

glTexCoord3f(0.0, 0.0, 1.0); glVertex3f(0.25, -1.0, 0.0);
glTexCoord3f(0.0, 1.0, 1.0); glVertex3f(0.25, 1.0, 0.0);
glTexCoord3f(1.0, 1.0, 0.0); glVertex3f(2.25, 1.0, 0.0);
glTexCoord3f(1.0, 0.0, 0.0); glVertex3f(2.25, -1.0, 0.0);
glEnd();
glFlush();
}

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-24 12:49

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表