opengl多个纹理 [英] opengl multiple textures

查看:105
本文介绍了opengl多个纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在场景中添加多个纹理,但我可以使用一种纹理,但是我也不知道如何包含其他纹理.

I'm wanting to add multiple textures to my scene I have one texture working but I don't know how to include other textures as well.

#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>

#include <stdlib.h>
#include <iostream> 

void init(void);
void display(void);
void keyboard(unsigned char, int, int);
void resize(int, int);
void drawcube(float, float, float, float, float, float, int);

int is_depth;

#define ROAD 0


struct Image 
{
    unsigned long size_x;
    unsigned long size_y;
    char *data;
};

typedef struct Image Image;

const int textureCount = 1;

Image myTextureData[textureCount];
GLuint theTexture[textureCount];


char* textureFilenames[textureCount] = {"road.bmp"};


int main (int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(600, 600);
    glutInitWindowPosition(40, 40);
    glutCreateWindow("3D World");
    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glEnable(GL_TEXTURE_2D);

    glutReshapeFunc(resize);  


    glutMainLoop();
    return 0;
}


int imageLoader(const char *filename, Image *image) 
{
    FILE *file;

    unsigned long size;
    unsigned long i;
    unsigned short int planes;
    unsigned short int bpp;

    char temp;
    char finalName[80];

    glTexCoord2f(1.0, 0.0);

    strcpy(finalName, "" );
    strcat(finalName, filename);

    if ((file = fopen(finalName, "rb"))==NULL) 
    {
        printf("File Not Found : %s\n",finalName);
        return 0;
    }

    fseek(file, 18, SEEK_CUR);

    glTexCoord2f(1.0, 0.0);

    if ((i = fread(&image->size_x, 4, 1, file)) != 1) 
    {
        printf("Error reading width from %s.\n", finalName);
        return 0;
    }

    if ((i = fread(&image->size_y, 4, 1, file)) != 1) 
    {
        printf("Error reading height from %s.\n", finalName);
        return 0;
    }

    size = image->size_x * image->size_y * 3;

    if ((fread(&planes, 2, 1, file)) != 1) 
    {
        printf("Error reading planes from %s.\n", finalName);
        return 0;
    }

    if (planes != 1) 
    {
        printf("Planes from %s is not 1: %u\n", finalName, planes);
        return 0;
    }

    if ((i = fread(&bpp, 2, 1, file)) != 1) 
    {
        printf("Error reading bpp from %s.\n", finalName);
        return 0;
    }

    if (bpp != 24) 
    {
        printf("Bpp from %s is not 24: %u\n", finalName, bpp);
        return 0;
    }

    fseek(file, 24, SEEK_CUR);

    image->data = (char *) malloc(size);

    if (image->data == NULL) 
    {
        printf("Error allocating memory for color-corrected image data");
        return 0;
    }

    if ((i = fread(image->data, size, 1, file)) != 1) 
    {
        printf("Error reading image data from %s.\n", finalName);
        return 0;
    }

    for (i=0;i<size;i+=3) 
    {
        temp = image->data[i];
        image->data[i] = image->data[i+2];
        image->data[i+2] = temp;
    }
    return 1;
}

void textureLoader() 
{

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    for(int k=0; k < textureCount; k++) 
    {
        if(!imageLoader(textureFilenames[k], &myTextureData[k])) 
            exit(1);


        glGenTextures(1, &theTexture[k]);

        glBindTexture(GL_TEXTURE_2D, theTexture[k]);


        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);
    }
}
void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_MODELVIEW);

    is_depth = 1;
}
void display(void)
{

    if (is_depth)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    else
        glClear(GL_COLOR_BUFFER_BIT);

    textureLoader();

    glBegin(GL_QUADS);
        glTexCoord2f(0.0,0.0);
        glVertex3f(-75.0, 0.0, -400.0);
        glTexCoord2f(0.0,1.0);
        glVertex3f(-75.0, 0.0, 100.0);
        glTexCoord2f(1.0,0.0);
        glVertex3f(75.0, 0.0, 100.0);
        glTexCoord2f(1.0,1.0);
        glVertex3f(75.0, 0.0, -400.0);

        drawcube(-70,15,72,8,15,28,4);
        drawcube(-70,10,10,8,10,28,0);
        drawcube(-70,15,-45,8,15,18,0);
        drawcube(-70,15,-85,8,15,18,0);
        drawcube(-70,35,-125,8,35,12,0);
        drawcube(-70,9,-170,8,9,28,0);
        drawcube(-70,15,-220,8,15,18,0);
        drawcube(-70,15,-265,8,15,28,0);
        drawcube(-70,15,-330,8,15,28,0);
        drawcube(67,15,72,8,15,28,0);
        drawcube(67,10,10,8,10,28,0);
        drawcube(67,15,-45,8,15,18,0);
        drawcube(67,15,-85,8,15,18,0);
        drawcube(67,35,-125,8,35,12,0);
        drawcube(67,9,-170,8,9,28,0);
        drawcube(67,15,-220,8,15,18,0);
        drawcube(67,15,-265,8,15,28,0);
        drawcube(67,15,-330,8,15,28,0);
        drawcube(-33,18,-364,25,18,10,0);
        drawcube(25,28,-364,30,28,10,0);
        drawcube(25,28,90,30,28,10,0);
        drawcube(-33,18,90,25,18,10,0);
        drawcube(0,60,-125,18,60,22,0);
        drawcube(0,25,-225,8,25,28,0);
        drawcube(0,25,0,8,25,28,0);




    glEnd();


    glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y)
{
    switch (key)
    {
    case 'a':
        glTranslatef(5.0, 0.0, 0.0);
        break;
    case 'd':
        glTranslatef(-5.0, 0.0, 0.0);
        break;
    case 'w':
        glTranslatef(0.0, 0.0, 5.0);
        break;
    case 's':
        glTranslatef(0.0, 0.0, -5.0);
        break;
    }
    display();
}

void resize(int width, int height)
{
    if (height == 0) height = 1;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0, width / height, 1.0, 400.0);
    glTranslatef(0.0, -5.0, -150.0);
    glMatrixMode(GL_MODELVIEW);
}

void drawcube(float xc, float yc, float zc, float x_offset, float y_offset, float z_offset, int color)
{

    switch(color)
    {
    case 1:
        glColor3f(1.0,0.0,0.0);
        break;
    case 2:
        glColor3f(0.0,1.0,0.0);
        break;
    case 3:
        glColor3f(0.0,0.0,1.0);
        break;
    }
    glBegin(GL_QUADS);
        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);

        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);

        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);


    glEnd();
}

推荐答案

我只注释您的代码

#include <windows.h>
#include <gl\gl.h>
#include <gl\glut.h>

#include <stdlib.h>
#include <iostream> 

void init(void);
void display(void);
void keyboard(unsigned char, int, int);
void resize(int, int);
void drawcube(float, float, float, float, float, float, int);

int is_depth;

#define ROAD 0

struct Image 
{
    unsigned long size_x;
    unsigned long size_y;
    char *data;
};

typedef struct Image Image;

const int textureCount = 1;

您正在使用const int进行数组大小调整.这告诉我,您正在使用C ++,那么为什么不为此使用STL std :: vector或std :: list?

You're using a const int for array sizeing. This tells me, you're using C++, so why don't you use STL std::vector or std::list for this?

Image myTextureData[textureCount];
GLuint theTexture[textureCount];
char* textureFilenames[textureCount] = {"road.bmp"};


int main (int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(600, 600);
    glutInitWindowPosition(40, 40);
    glutCreateWindow("3D World");
    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);

    glEnable(GL_TEXTURE_2D);

根据需要设置OpenGL状态. glEnable在这里毫无意义.

OpenGL state is set on demand. That glEnable makes no sense here.

    glutReshapeFunc(resize);  


    glutMainLoop();
    return 0;
}


int imageLoader(const char *filename, Image *image) 
{
    FILE *file;

    unsigned long size;
    unsigned long i;
    unsigned short int planes;
    unsigned short int bpp;

    char temp;
    char finalName[80];

    glTexCoord2f(1.0, 0.0);

WTF ?!您如何在纹理 loader 中称呼glTexCoord?这是一个绘图命令.

WTF?! What for do you call glTexCoord in the texture loader? It's a drawing command.

    strcpy(finalName, "" );
    strcat(finalName, filename);

WTF ?!您要复制filename的目的是什么?另外80个字符可能还不够.

WTF?! what do you copy filename for? Also 80 characters will probably not be sufficient.

    if ((file = fopen(finalName, "rb"))==NULL) 
    {

未正确打开文件的原因可能不仅仅是错误的路径.

A file not being properly opened can have a lot more reasons than just a wrong path.

        printf("File Not Found : %s\n",finalName);
        return 0;
    }

    fseek(file, 18, SEEK_CUR);

假设您所期望的是文件,则不要盲目尝试读取文件.二进制文件(例如您要在此处尝试读取的DIB)具有标头是有原因的,因此您也绝对应该阅读并解析该标头!

You shouldn't mindlessly try to read a file, assuming it is what you expect. Binary files, like the DIB you're trying to read here have headers for a reason, so you should definitely read and parse this header, too!

    glTexCoord2f(1.0, 0.0);

再次?!

    if ((i = fread(&image->size_x, 4, 1, file)) != 1) 
    {
        printf("Error reading width from %s.\n", finalName);
        return 0;
    }

    if ((i = fread(&image->size_y, 4, 1, file)) != 1) 
    {
        printf("Error reading height from %s.\n", finalName);
        return 0;
    }

假设系统的字节序和对齐规则与文件格式匹配,您正在从文件中读取值?你一定有钢球!

You're reading values from a file, assuming your system's endianess and alignment rule match the file format? You must've got balls of steel!

    size = image->size_x * image->size_y * 3;

整数溢出,是的!您刚刚使程序可以被利用.

Integer overflow, yeah! You just made your program exploitable.

    if ((fread(&planes, 2, 1, file)) != 1) 
    {
        printf("Error reading planes from %s.\n", finalName);
        return 0;
    }

    if (planes != 1) 
    {
        printf("Planes from %s is not 1: %u\n", finalName, planes);
        return 0;
    }

    if ((i = fread(&bpp, 2, 1, file)) != 1) 
    {
        printf("Error reading bpp from %s.\n", finalName);
        return 0;
    }

重新读取二进制值,而没有适当地注意字节序和对齐方式...

Again reading binary values w/o properly caring for endianess and alignment...

    if (bpp != 24) 
    {
        printf("Bpp from %s is not 24: %u\n", finalName, bpp);
        return 0;
    }

    fseek(file, 24, SEEK_CUR);

您为什么在这里进行相对寻找? BITMAPFILEHEADER(您知道您之前无意间跳过的那18个字节)会告诉您像素数据的确切位置.

Why do you perform a relative seek here? The BITMAPFILEHEADER (you know those 18 bytes you mindlessly skipped previously) tells you where exactly the pixeldata starts.

    image->data = (char *) malloc(size);

    if (image->data == NULL) 
    {
        printf("Error allocating memory for color-corrected image data");
        return 0;
    }

    if ((i = fread(image->data, size, 1, file)) != 1) 
    {
        printf("Error reading image data from %s.\n", finalName);
        return 0;
    }

顺便说一句:如果中止,您应该关闭文件.

BTW: You should close the file if aborting.

    for (i=0;i<size;i+=3) 
    {
        temp = image->data[i];
        image->data[i] = image->data[i+2];
        image->data[i+2] = temp;
    }

这不是进行颜色校正,它只是交换元素.较新的OpenGL直接支持DIB文件的BGR对齐.

This is not doing a colour correction, it just swaps elements. Newer OpenGL directly support the BGR alignment of DIB files.

    return 1;

仍然没有关闭文件...

Still not closing the file...

}

void textureLoader() 
{

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    for(int k=0; k < textureCount; k++) 
    {
        if(!imageLoader(textureFilenames[k], &myTextureData[k])) 
            exit(1);

好吧,通过这些全局数组完成这项工作.但请注意,textureLoader应该返回已加载纹理的纹理ID.

Well, okay, doing it through those global arrays does the job. But seriously: textureLoader should return the texture ID of the loaded texture.

        glGenTextures(1, &theTexture[k]);

        glBindTexture(GL_TEXTURE_2D, theTexture[k]);    

        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);

        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);
    }
}

void init(void)
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glMatrixMode(GL_MODELVIEW);

    is_depth = 1;
}

您在此处初始化"的内容属于显示功能.

What you "initialize" here belongs into the display function.

void display(void)
{

    if (is_depth)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    else
        glClear(GL_COLOR_BUFFER_BIT);

这是WTF吗?您认为这有什么作用?是的,有多种通过技术只能部分清除帧缓冲区,但您并没有这样做.摆脱is_depth.

WTF was this? What effect do you think does this have? Yes there are multipass techniques clearing the framebuffer only partially, but you're not doing such. Get rid of is_depth.

    textureLoader();

textureLoader属于init;无论如何,加载纹理顶点缓冲对象是OpenGL初始化程序"唯一可以做的事情.有了更多的经验,您也可以从显示路线开始做这些事情,以实现交错纹理加载之类的东西,以便您可以在没有加载延迟的情况下导航大型场景.

textureLoader belongs into init; loading textures and vertex buffer objects is the only usefull thing an OpenGL "initializer" can do anyways. With more experience you start to do such things from the display routing as well, to implement stuff like staggered texture loading, so that you can navigate large scenes without loading delays.

这里缺少重要的事情:您没有设置矩阵.在渲染函数中应同时设置 projection modelview 转换矩阵.

Something important is missing here: You don't set up your matrices. Both the projection and the modelview transformation matrices should be set in the rendering function.

因此,您想绘制带纹理的四边形.那你为什么不呢?

So you want to draw textured quads. So why don't you:

  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D, theTexture[0]);还是您要在此处使用的任何ID?

  • glEnable(GL_TEXTURE_2D);
  • glBindTexture(GL_TEXTURE_2D, theTexture[0]); or whichever ID you want to use here?

glBegin(GL_QUADS);
    glTexCoord2f(0.0,0.0);
    glVertex3f(-75.0, 0.0, -400.0);
    glTexCoord2f(0.0,1.0);
    glVertex3f(-75.0, 0.0, 100.0);
    glTexCoord2f(1.0,0.0);
    glVertex3f(75.0, 0.0, 100.0);
    glTexCoord2f(1.0,1.0);
    glVertex3f(75.0, 0.0, -400.0);

到目前为止看起来还不错,除了您不提供正常值.您将需要这些来照明.

Looking good so far, except that you don't supply normals. You'll need those for lighting.

但是WTF是这样的:

        drawcube(-70,15,72,8,15,28,4);
        drawcube(-70,10,10,8,10,28,0);
        drawcube(-70,15,-45,8,15,18,0);
        drawcube(-70,15,-85,8,15,18,0);
        drawcube(-70,35,-125,8,35,12,0);
        drawcube(-70,9,-170,8,9,28,0);
        drawcube(-70,15,-220,8,15,18,0);
        drawcube(-70,15,-265,8,15,28,0);
        drawcube(-70,15,-330,8,15,28,0);
        drawcube(67,15,72,8,15,28,0);
        drawcube(67,10,10,8,10,28,0);
        drawcube(67,15,-45,8,15,18,0);
        drawcube(67,15,-85,8,15,18,0);
        drawcube(67,35,-125,8,35,12,0);
        drawcube(67,9,-170,8,9,28,0);
        drawcube(67,15,-220,8,15,18,0);
        drawcube(67,15,-265,8,15,28,0);
        drawcube(67,15,-330,8,15,28,0);
        drawcube(-33,18,-364,25,18,10,0);
        drawcube(25,28,-364,30,28,10,0);
        drawcube(25,28,90,30,28,10,0);
        drawcube(-33,18,90,25,18,10,0);
        drawcube(0,60,-125,18,60,22,0);
        drawcube(0,25,-225,8,25,28,0);
        drawcube(0,25,0,8,25,28,0);

您在这里的glBegin(…)...glEnd()块中,因此唯一有效的OpenGL调用是glColor,glNormal,glTexCoord,glVertexAttrix,glVertex和glEnd.那么,让我们看看drawcube中有什么...

You're in a glBegin(…)...glEnd() block here, so the only valid OpenGL calls are glColor, glNormal, glTexCoord, glVertexAttrix, glVertex and glEnd. So let's see what's in drawcube then...

    glEnd();


    glutSwapBuffers();
}

void keyboard(unsigned char key, int x, int y)
{
    switch (key)
    {
    case 'a':
        glTranslatef(5.0, 0.0, 0.0);
        break;
    case 'd':
        glTranslatef(-5.0, 0.0, 0.0);
        break;
    case 'w':
        glTranslatef(0.0, 0.0, 5.0);
        break;
    case 's':
        glTranslatef(0.0, 0.0, -5.0);
        break;
    }
    display();
}

不!不!不!这不是OpenGL的工作方式. glTranslate是矩阵处理函数,只有在渲染过程中才能正确使用.您只是在这里弄乱了OpenGL状态.

NO! NO! NO! This is not how OpenGL works. glTranslate is a matrix manipulation function and it's only proper use is in the context of a rendering pass. You're just messing with the OpenGL state here.

void resize(int width, int height)
{
    if (height == 0) height = 1;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0, width / height, 1.0, 400.0);
    glTranslatef(0.0, -5.0, -150.0);
    glMatrixMode(GL_MODELVIEW);

这东西属于展示.我知道,很多(大多数)教程都像您那样编写它,但是请相信我:一旦您想要实现HUD或多遍渲染之类的设置,在调整大小处理程序中设置投影就会咬住您.

This stuff belongs into display. I know, many (most) tutorials write it that way, like you, but trust me: As soon as you want to implement something like a HUD or multipass rendering setting the projection in the resize handler will bite you.

}

void drawcube(float xc, float yc, float zc, float x_offset, float y_offset, float z_offset, int color)
{

啊,drawcube函数

Ahh, the drawcube function

    switch(color)
    {
    case 1:
        glColor3f(1.0,0.0,0.0);
        break;
    case 2:
        glColor3f(0.0,1.0,0.0);
        break;
    case 3:
        glColor3f(0.0,0.0,1.0);
        break;
    }

    glBegin(GL_QUADS);

您正在从glBegin(…)...glEnd()块中调用drawcube,但是然后尝试打开另一个块.这是OpenGL错误. glBegin(…)...glEnd()不要嵌套.

You're calling drawcube from within a glBegin(…)...glEnd() block, but then try to open another block. This is an OpenGL error. glBegin(…)...glEnd() don't nest.

        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);

        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);

        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc - z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc - z_offset);

        glVertex3f(xc + x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc + y_offset,zc + z_offset);
        glVertex3f(xc - x_offset,yc - y_offset,zc + z_offset);
        glVertex3f(xc + x_offset,yc - y_offset,zc + z_offset);

您不是在问如何使用纹理吗?我看不到那里的glTexCoord呼叫...

Wasn't your question how to use textures? I don't see calls to glTexCoord up there...

    glEnd();
}

这篇关于opengl多个纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆