Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. Unable to properly load PPM texture data

Unable to properly load PPM texture data

Scheduled Pinned Locked Moved Graphics
graphicsjsonquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cyrilix
    wrote on last edited by
    #1

    I'm trying to turn my PPM (lossless image file) into a texture, but the texture is not showing up correctly. I've tried loading a bitmap image as a texture using glaux and a call to auxDIBImageLoad(), however, I would simply like to implement my own parser for PPM. Basically, in PPM, the line after the getting the value for "int maxValue" is a long line of binary data that stores the 8-bit RGB (total 24 bits) going from left to right, top to bottom in the image. If we think about this in a 2D coordinate system, parsing the file would first get you (x, y) = (0, 0), then (1, 0), then (2, 0), until the end of the width, then (0, 1), and etc. Knowing this, does anyone know why my texture is being parsed incorrectly?

    ifstream texFile("brickbump.ppm");
    if (texFile.is_open())
    {
    //Load texture properties
    char propBuf[8];
    texFile.getline(propBuf, 8);
    string format = propBuf;
    texFile.getline(propBuf, 8);
    int x = atoi(propBuf);
    texFile.getline(propBuf, 8);
    int y = atoi(propBuf);
    texFile.getline(propBuf, 8);
    int maxValue = atoi(propBuf);

    //Load texture data
    char\* texArray = new char\[3 \* x \* y\];
    int count = 0;
    while (!texFile.eof())
    {
    	texFile.get(texArray\[count\]);
    	count++;
    }
    
    //Generate textures
    glGenTextures(1, &m\_textures\[0\]);
    glBindTexture(GL\_TEXTURE\_2D, m\_textures\[0\]);
    glTexImage2D(GL\_TEXTURE\_2D, 0, GL\_RGB, x, y, 0, GL\_RGB, GL\_UNSIGNED\_BYTE, texArray);
    glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MIN\_FILTER, GL\_LINEAR);
    glTexParameteri(GL\_TEXTURE\_2D, GL\_TEXTURE\_MAG\_FILTER, GL\_LINEAR);
    
    delete \[\] texArray;
    

    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups