Results 1 to 6 of 6

Thread: glTexImage & .pgm

  1. #1
    Member Contributor
    Join Date
    May 2008
    Posts
    67

    glTexImage & .pgm

    Yes! I'm using a .pgm .ie, each 8 bit set contains a joint color value of RGB, so 255 = black and 0 = white.

    Having trouble figuring out what Parameters I shud specify for glTextImage. in the format and internalformat fields

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, myTexture);

  2. #2
    Member Contributor
    Join Date
    May 2008
    Posts
    67

    Re: glTexImage & .pgm

    Ok I have just specified GL_RED in the 3rd to last field. Seems to work. I also want to make all the white pixels i.e 0 in the pgm file, transperant, I have setup this:

    glEnable(GL_BLEND);
    glEnable(GL_ALPHA_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glAlphaFunc(GL_GREATER, 0.9f);

    Not sure how I set the alpha value to zero in the pgm for each pixel with a color of 0. Its kind of hard of course because each pixel has only an 8bit field.

  3. #3
    Senior Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: glTexImage & .pgm

    If I understand you well, you read a monochrome image and you want only shade of red. To gain alpha what I would do is to convert the the image R => RGBA.

    Example:
    If your image data have 4 pixels

    0 => 0,0,0,0
    100 => 100,0,0,255
    125 => 125,0,0,255
    200 => 200,0,0,255

    You waste a little video memory but I think you can now use GL_DECAL for GL_TEXTURE_ENV_MODE.

    hope it help.

  4. #4
    Member Contributor
    Join Date
    May 2008
    Posts
    67

    Re: glTexImage & .pgm

    Hey thanks, I can't load the image using glTexImage as RGBA as it has a runtime error. I also want a shade of black not red.

    Thanks for your help.

  5. #5
    Senior Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: glTexImage & .pgm

    Ok, my example is now

    0 => 0,0,0,0
    100 => 100,100,100,255
    125 => 125,125,125,255
    200 => 200,200,200,255

    original size new size
    4 bytes <=> 16 bytes

    You have a runtime error because you still feed glTexImage2D with
    the original array of pixel with GL_RGBA so a buffer overflow occur.



    Look at my inner loop for reading a pgm file

    Code :
    //allocate image data for 
    //glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,image_width,image_height,0,GL_RGBA,GL_UNSIGNED_BYTE,data); data = new unsigned char[image_width*image_height*4];//GL_RGBA format
    	  unsigned char pgm_pixel_data;
     
    	  int i,data_indice;
    	  for(i = 0 ,data_indice = 0  ; i < image_width*image_height ; i++)
    	{
    	  read>>pgm_pixel_data;
    	//  cout<<pgm_pixel_data<<endl;
    	  if(pgm_pixel_data!=0)//pixel is opaque (grey scale)
    	    {
    	      data[data_indice++] = pgm_pixel_data; //R
    	      data[data_indice++] = pgm_pixel_data; //G
    	      data[data_indice++] = pgm_pixel_data; //B
    	      data[data_indice++] = 255; //A
    	    }
    	  else//pixel is transparent
    	    {
    	      data[data_indice++] = 0; //R
    	      data[data_indice++] = 0; //G
    	      data[data_indice++] = 0; //B
                  data[data_indice++] = 0; //A
    	    }
    	}


    This work well. (no runtime error)

  6. #6
    Member Contributor
    Join Date
    May 2008
    Posts
    67

    Re: glTexImage & .pgm

    hey, I implemented it at it worked beautifully. This is a real help to me as I am just coming to terms with all of the main features of open gl. so thanks ALOT for your time!!


Similar Threads

  1. Replies: 8
    Last Post: 01-27-2015, 06:20 AM
  2. quick question about PBO's and glTexImage
    By vhammer in forum OpenGL: Basic Coding
    Replies: 19
    Last Post: 06-14-2012, 01:30 PM
  3. glTexImage with integer creates INVALID OPERATION
    By bdysk in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-03-2010, 09:43 AM
  4. internal format in glTexImage*()
    By sguTiger in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-29-2009, 08:09 AM
  5. glTexImage* with width/height == 0
    By Jens Scheddin in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 03-01-2007, 03:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean