简体   繁体   English

如何在 opengl 中对 3d 树进行纹理处理

[英]How to texture a 3d tree in opengl

I've tried to texture a tree with a *.bmp image and something I do wrong...Please help me...I have an error: undeclared identifier GL_TEXTURE_3D我尝试使用 *.bmp 图像对树进行纹理处理,但我做错了...请帮助我...我有一个错误:未声明的标识符 GL_TEXTURE_3D

void myinit(void);
void CALLBACK display(void);
void CALLBACK myReshape(GLsizei w, GLsizei h);
void load_texture(const char* s);
float baseRadius = 0.10;
float topRadius = 0.10;
float height = 1.0;
int slices=50, stacks=50;
float pi = 3.14159265358979323846;

GLuint IDtextura;

void load_texture(const char* s)
{   
    AUX_RGBImageRec *pImagineTextura = auxDIBImageLoad(s);

    if(pImagineTextura != NULL )
    {
        glGenTextures( 1, &IDtextura );

        glBindTexture(GL_TEXTURE_3D, IDtextura);

        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);


        glTexImage3D(GL_TEXTURE_3D, 0, 3, pImagineTextura->sizeX, pImagineTextura->sizeY,pImagineTextura->sizeZ,
            0, GL_RGB, GL_UNSIGNED_BYTE, pImagineTextura->data);
    }

    if(pImagineTextura)
    {
        if(pImagineTextura->data )
            free(pImagineTextura->data );

        free(pImagineTextura);
    }

}
void myinit (void)
{    
    glClearColor(1.0, 1.0, 1.0, 1.0);
     glEnable(GL_TEXTURE_3D);
    glShadeModel(GL_FLAT);
}

void CALLBACK display(void)
{
    GLUquadricObj* cilindru;
    cilindru = gluNewQuadric();

    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glTranslatef (0.0, 0.0, -5.0);
    const char* sir;
    GLuint ID1;
        glClearColor(1.0, 1.0, 1.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    sir=".\\mm.bmp";
    load_texture(sir);
    ID1=IDtextura;


    glBindTexture( GL_TEXTURE_3D, ID1);
    //glBegin(GL_QUADS);
        //????
    glEnd();

    glPushMatrix ();
    glRotated (0.0, 1.0, 0.0, 0.0);
    glTranslated (0.0, 0.0, 1.5);
    glDisable (GL_LIGHTING);
    glEnable (GL_LIGHTING);
    glPopMatrix ();

    //tree
    glPushMatrix();
        glRotatef(90, 1, 0, 0);
        gluQuadricDrawStyle(cilindru, GLU_FILL);
        gluCylinder(cilindru, baseRadius, topRadius, height, slices,stacks);
    glPopMatrix();

    ..........

A.bmp file is a 2D image... So you don't even have to use GL_TEXTURE_3D. A.bmp 文件是 2D 图像...所以您甚至不必使用GL_TEXTURE_3D。

What you want to do is UV mapping.你想做的是UV映射。 Texturing a 3D object doesn't require a 3D texture.纹理 3D object 不需要 3D 纹理。

Remove glTexImage3D, use glTexImage2D instead.删除 glTexImage3D,改用 glTexImage2D。 Same thing for glTexCoord3f. glTexCoord3f 也一样。

What's more, giving 300 lines of unformatted code without real question (what you want, what you tried, etc) isn't likely to give you an answer ( But it's ok, it's your first time here )更重要的是,给出 300 行无格式代码而没有真正的问题(你想要什么,你尝试过什么等)不太可能给你答案(但没关系,这是你第一次来这里)

3D textures are part of OpenGL 1.2. 3D 纹理是 OpenGL 1.2 的一部分。 On windows, in order to use OpenGL versions higher than 1.1 you need external library such as GLEW or GLee .在 windows 上,为了使用高于 1.1 的 OpenGL 版本,您需要外部库,例如GLEWGLee

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM