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 6 of 6

Thread: textures?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    102

    textures?

    How do I import textures? Is there any easy way, does somebody have any kind of xtra libraries or something??? And as a subquestion, whats an arc fillet, and how do I use one???
    CyBBe

  2. #2
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: textures?

    Import textures, just load a bitmap ... it's no harder than that.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    102

    Re: textures?

    Exactly how do I import a bitmap, I asked for an easy way, can U give me some code examples???
    CyBBe

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2000
    Location
    ...
    Posts
    26

    Re: textures?

    hi,
    check this out...
    www.codeguru.com
    nehe.gamedev.net

  5. #5
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    102

    Re: textures?

    Someone else, som xtra libraries???
    CyBBe

  6. #6
    Junior Member Regular Contributor
    Join Date
    Feb 2000
    Location
    Brisbane,QLD, Australia
    Posts
    107

    Re: textures?

    Originally posted by CyBBe:
    Someone else, som xtra libraries???
    Here you go.. This should tide you over for awhile.
    ///////////////////////////////////////////////////////////////////////////////
    // This function loads a 24-bit color (RGB)Windows bitmap and sets it as the current
    // texture. The bitmap must be 24-bit color, and the dimensions must be powers
    // of 2 (no additional checks are performed).
    ///////////////////////////////////////////////////////////////////////////////

    loadBitmap(char* filename)
    {
    FILE* bmpfile;
    BITMAPFILEHEADER bmfileheader;
    BITMAPINFOHEADER bminfoheader;
    RGBTRIPLE rgb;

    int nTextureWidth;
    int nTextureHeight;
    int i,j,texpos = 0;
    BYTE *pBitmapData;

    bmpfile = fopen(filename, "rb");

    if (!bmpfile)
    exit(1);

    fread(&bmfileheader, sizeof(BITMAPFILEHEADER), 1, bmpfile);
    fread(&bminfoheader, sizeof(BITMAPINFOHEADER), 1, bmpfile);


    nTextureWidth = bminfoheader.biWidth;
    nTextureHeight = bminfoheader.biHeight;

    pBitmapData = (GLubyte*)malloc(nTextureWidth * nTextureHeight *3);

    // read color
    for (i = 0; i < nTextureWidth; i++)
    {
    for(j = nTextureHeight - 1; j>=0 ; j--) //start with the height because the first data you read in the color array of the bitmap
    { // is coord (1.0).
    fread(&rgb, sizeof(RGBTRIPLE),1,bmpfile);
    pBitmapData[texpos] = rgb.rgbtRed ;
    pBitmapData[texpos+1] = rgb.rgbtGreen;
    pBitmapData[texpos+2] = rgb.rgbtBlue;
    }
    }
    fclose(bmpfile);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nTextureWidth, nTextureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pBitmapData);
    return TRUE;

    }


    [This message has been edited by dans (edited 03-27-2000).]

Posting Permissions

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