Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Problem in Texture Render to a box

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Location
    seoul, south korea
    Posts
    14

    Exclamation Problem in Texture Render to a box

    Hello folks I need urgent help I am near to my deadline I am working on a small project similar to bloxorz. In this project the rendered box texture is not visible, I had used nehe opengl code to load bmp image and I had used same logic for render the box but I don't know where I am lacking please need a help.
    I am pasting code below of Texture load of an image and draw the box funtions and attached the output photo. Please need good suggestions. Thanks in advance.

    AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
    {
    FILE *File=NULL; // File Handle

    if (!Filename) // Make Sure A Filename Was Given
    {
    return NULL; // If Not Return NULL
    }

    File=fopen(Filename,"r"); // Check To See If The File Exists

    if (File) // Does The File Exist?
    {
    fclose(File); // Close The Handle
    return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
    }

    return NULL; // If Load Failed Return NULL
    }

    int LoadGLTextures() // Load Bitmaps And Convert To Textures
    {
    int Status=FALSE; // Status Indicator

    AUX_RGBImageRec *TextureImageBox[1]; // Create Storage Space For The Texture

    memset(TextureImageBox,0,sizeof(void *)*1); // Set The Pointer To NULL

    // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    if (TextureImageBox[0]=LoadBMP("Data/Crate.bmp"))
    {
    Status=TRUE; // Set The Status To TRUE

    glGenTextures(3, &texturebox[0]); // Create Three Textures

    // Create Nearest Filtered Texture
    glBindTexture(GL_TEXTURE_2D, texturebox[0]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImageBox[0]->sizeX, TextureImageBox[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImageBox[0]->data);

    // Create Linear Filtered Texture
    glBindTexture(GL_TEXTURE_2D, texturebox[1]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImageBox[0]->sizeX, TextureImageBox[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImageBox[0]->data);

    // Create MipMapped Texture
    glBindTexture(GL_TEXTURE_2D, texturebox[2]);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImageBox[0]->sizeX, TextureImageBox[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImageBox[0]->data);
    }

    if (TextureImageBox[0]) // If Texture Exists
    {
    if (TextureImageBox[0]->data) // If Texture Image Exists
    {
    free(TextureImageBox[0]->data); // Free The Texture Image Memory
    }

    free(TextureImageBox[0]); // Free The Image Structure
    }

    return Status; // Return The Status
    }
    ////////////////////////////////Texture//////////////////////////////////
    int DrawGLBox(GLvoid) // Here's Where We Do All The Drawing
    {
    glPushMatrix();
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glNormal3f(0,0,1);
    //glTexCoord2f(0,1);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-2,0,4);
    //glTexCoord2f(0,0);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(-2,0,0);
    //glTexCoord2f(1,0);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0,0,0);
    //glTexCoord2f(1,1);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0,0,4);

    glNormal3f(0,0,-1);
    //glTexCoord2f(1,1);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(-2,2,4);
    //glTexCoord2f(0,1);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0,2,4);
    //glTexCoord2f(0,0);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0,2,0);
    //glTexCoord2f(1,0);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-2,2,0);

    glNormal3f(-1,0,0);
    //glTexCoord2f(0,1);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-2,0,4);
    //glTexCoord2f(0,0);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-2,2,4);
    //glTexCoord2f(1,0);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(-2,2,0);
    //glTexCoord2f(1,1);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(-2,0,0);

    glNormal3f(1,0,0);
    //glTexCoord2f(0,1);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0,0,4);
    //glTexCoord2f(1,1);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0,0,0);
    //glTexCoord2f(1,0);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0,2,0);
    //glTexCoord2f(0,0);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0,2,4);

    glNormal3f(0,1,0);
    //glTexCoord2f(0,1);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(-2,2,4);
    //glTexCoord2f(0,0);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(-2,0,4);
    //glTexCoord2f(1,0);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(0,0,4);
    //glTexCoord2f(1,1);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(0,2,4);

    glNormal3f(0,-1,0);
    //glTexCoord2f(0,1);
    glTexCoord2f(0.0f, 0.0f);
    glVertex3f(-2,2,0);
    //glTexCoord2f(0,0);
    glTexCoord2f(1.0f, 0.0f);
    glVertex3f(0,2,0);
    //glTexCoord2f(1,0);
    glTexCoord2f(1.0f, 1.0f);
    glVertex3f(0,0,0);
    //glTexCoord2f(1,1);
    glTexCoord2f(0.0f, 1.0f);
    glVertex3f(-2,0,0);

    glEnd();
    glDisable(GL_TEXTURE_2D);
    glPopMatrix();

    return TRUE; // Keep Going
    }int DrawGLScene(GLvoid)
    {
    int i=0;

    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D,texture[0]);
    if(Num==0)
    {
    TheApp.DrawMap1();
    }
    if(Num==1)
    {
    TheApp.DrawMap2();
    }
    TheApp.globalmoves= moves;

    glBindTexture(GL_TEXTURE_2D,texturebox[filter]);
    glTranslatef(TheApp.BoxX,TheApp.BoxY,0);


    KeyControl();
    Wining();

    if(First==TRUE)
    {
    First=FALSE;
    return TRUE;
    }
    //////////////////MovingBox////////////////////////
    if(TheApp.chain==PATH)
    {
    glTranslatef(0,0,2);
    glRotatef(-90,0,1,0);
    DrawGLBox();
    }
    else if(TheApp.chain==distance)
    {
    DrawGLBox();
    }
    else if(TheApp.chain==SPATH)
    {
    glTranslatef(0,0,2);
    glRotatef(-90,1,0,0);
    DrawGLBox();
    }
    else if(TheApp.chain==XPATH)
    {
    glRotatef(90,1,0,0);
    DrawGLBox();
    }

    return TRUE;
    }
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	blox.jpg 
Views:	70 
Size:	9.9 KB 
ID:	890  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •