Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: BMP texture Mapping appears pale

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    22

    BMP texture Mapping appears pale

    Hi all,

    My texture mapping makes the mapped BMP look very pale. This is my code:

    Code :
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
       glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
       gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
    Any reason why that would appear pale? Thanks

  2. #2
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: BMP texture Mapping appears pale

    Just a guess, but perhaps your texture is pale?

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    22

    Re: BMP texture Mapping appears pale

    You mean the bitmap being pale? Its not its much darker than when it is displayed using OpenGL?

  4. #4
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: BMP texture Mapping appears pale

    Can you please post the complete code and perhaps a screenshot (extra points for that )?

  5. #5
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: BMP texture Mapping appears pale

    In the future, when you have trouble like this, it's really helpful if you can paint as complete a picture as possible, to help others identify the trouble you're having as quickly as possible, and with a minimum of Q&A. This saves everyone some time, and helps keeps the discussion productive.

    Hope this helps.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    22

    Re: BMP texture Mapping appears pale

    Rendered Scene Code:

    Code :
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		
    glPopMatrix();
    	glEnable(GL_TEXTURE_2D);	
    	Texture t = Texture();
    	int i = t.LoadBitmapW("c:/b.bmp");
    	glBindTexture(GL_TEXTURE_2D, i);
     
    	//DRAW THE BACKGROUND
    	glBegin(GL_POLYGON);
    		glTexCoord2f(0.0,0.0);glVertex3f(0.0,0.0,0.0);
    		glTexCoord2f(1.0,0.0);glVertex3f(1.0,0.0,0.0);
    		glTexCoord2f(1.0,1);glVertex3f(1.0,1,0.0);
    		glTexCoord2f(0.0,1);glVertex3f(0.0,1,0.0);		
    	glEnd();
    glPopMatrix();
    glSwapBuffers();
    	glFlush();
    Main Code:
    Code :
    void main (int argc, char** argv)
    {
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    	glutInitWindowPosition(100,100);
    	glutInitWindowSize(800,600);
    	glutCreateWindow("Example");
    	glutDisplayFunc(renderScene);
    //	glutIdleFunc(renderScene);	
    	glutReshapeFunc(changeSize);
    	glutSpecialFunc(processSpecialKeys);
     
    	// enable depth testing
    	glEnable(GL_DEPTH_TEST);
    	glutMainLoop();
    }
    Texture Loading Code:
    Code :
    int Texture::LoadBitmap(char *filename) 
    {
     
       unsigned char *l_texture;
       int i, j=0;
       FILE *l_file;
       BITMAPFILEHEADER fileheader; 
       BITMAPINFOHEADER infoheader;
       RGBTRIPLE rgb;
       num_texture++;
     
       if( (l_file = fopen(filename, "rb"))==NULL) return (-1);
       fread(&fileheader, sizeof(fileheader), 1, l_file);
       fseek(l_file, sizeof(fileheader), SEEK_SET);
       fread(&infoheader, sizeof(infoheader), 1, l_file);
     
       l_texture = (BYTE *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
       memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);
       glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
     
       for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
       { 
          fread(&amp;rgb, sizeof(rgb), 1, l_file); 
     
          l_texture[j+0] = rgb.rgbtRed; // Red component
          l_texture[j+1] = rgb.rgbtRed; // Green component
          l_texture[j+2] = rgb.rgbtBlue; // Blue component
          l_texture[j+3] = 255; // Alpha value
          j += 4; // Go to the next position
       }
       fclose(l_file);
       glBindTexture(GL_TEXTURE_2D, num_texture);
     
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
       glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
       gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
       free(l_texture);
       return num_texture;
     
    }
    Screen View Code:

    Code :
    // Prevent a divide by zero, when window is too short
    	// (you cant make a window of zero width).
    	if(h == 0)
    		h = 1;
     
    	float ratio = 1.0* w / h;
     
    	// Reset the coordinate system before modifying
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	// Set the viewport to be the entire window
    	glViewport(0,0, w, h);
     
    	// Set the correct perspective.
    	gluPerspective(45,ratio,1,1000);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();  
    	gluLookAt(0.5,0.5,1.2, 0.5,0.5,0.0, 0.0,1.0,0.0);
    Right theres the simplified version of the code because the real code is very long.

    This is the ouput I get when i run the program

    Image 1

    This is the texture getting mapped
    Image 2

    As i said thats the basic version of the code but its still giving pale images.

    And my apologies for the lack of info during my first post. I thought the reason why I was getting pale images was due to the Variables I was using in the original code which were decreasing image quality for faster performance and i thought that someone could quickly point where i was going wrong from the code i posted.

    Hope this helps, if not explain what else you require

    Thanks for your help

  7. #7
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: BMP texture Mapping appears pale

    I'm sorry, I guess you missed the point. If you post the complete code, then I can just copy and paste it in an empty project real quick and build it.

    I understand if you're unwilling or unable to do that, but unfortunately I don't have time to debug code snippits.

  8. #8
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: BMP texture Mapping appears pale

    If you want, you can email me the program and I'll look at it for you. I mean complete program, though, paste and build style

  9. #9
    Junior Member Newbie
    Join Date
    Aug 2006
    Posts
    22

    Re: BMP texture Mapping appears pale

    Thankyou very much mate.

    The following code compiles fine, with unicode off in VS2005.

    Lesson1.cpp

    Code :
    #include "stdafx.h"
    #include "GL/glut.h"
    #include "texture.h"
    #include <stdlib.h>
     
     
    #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )  
    bool first = true;
     
    void changeSize(int w, int h) {
     
    	// Prevent a divide by zero, when window is too short
    	// (you cant make a window of zero width).
    	if(h == 0)
    		h = 1;
     
    	float ratio = 1.0* w / h;
     
    	// Reset the coordinate system before modifying
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
     
    	// Set the viewport to be the entire window
    	glViewport(0,0, w, h);
     
    	// Set the correct perspective.
    	gluPerspective(45,ratio,1,1000);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();  
    	gluLookAt(0.5,0.5,1.2, 0.5,0.5,0.0, 0.0,1.0,0.0);
    }
    void renderScene(void){
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		
    	glPushMatrix();
     
    	glEnable(GL_TEXTURE_2D);
    	if(first){
    		Texture t = Texture();
    		int i = t.LoadBitmap("c:/b.bmp");
     
    	}
     
    	glBindTexture(GL_TEXTURE_2D, 1);
    	//DRAW THE BACKGROUND
    	glBegin(GL_POLYGON);
    		glTexCoord2f(0.0,0.0);
    		glVertex3f(-0.16,0.0,0.0);
    		glTexCoord2f(1.0,0.0);
    		glVertex3f(1.16,0.0,0.0);
    		glTexCoord2f(1.0,1);
    		glVertex3f(1.16,1.0,0.0);
    		glTexCoord2f(0.0,1);
    		glVertex3f(-0.16,1.0,0.0);		
    	glEnd();
    	glPopMatrix();
     
    	glutSwapBuffers();
    	glFlush();	
     
    }
     
     
     
    void main (int argc, char** argv)
    {
    	glutInit(&amp;argc, argv);
    	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    	glutInitWindowPosition(100,100);
    	glutInitWindowSize(800,600);
    	glutCreateWindow("Example");
    	glutDisplayFunc(renderScene);
    //	glutIdleFunc(renderScene);	
    	glutReshapeFunc(changeSize);
    //	glutSpecialFunc(processSpecialKeys);
     
    	// enable depth testing
    	glEnable(GL_DEPTH_TEST);
    	glutMainLoop();
    }
    Lesson1.h

    Code :
    #pragma once
    Texture.h

    Code :
    #pragma once
     
    class Texture
    {
    public:
    	Texture(void);
    	int LoadBitmap(char *filname);
    public:
    	virtual ~Texture(void);
    };
    Texture.cpp

    Code :
    #include "StdAfx.h"
    #include "Texture.h"
    #include <fstream>
    #include "windows.h"
    #include "GL/glut.h"
     
    int num_texture = 0;
     
    Texture::Texture(void)
    {
    }
     
    Texture::~Texture(void)
    {
    }
     
    int Texture::LoadBitmap(char *filename) 
    {
     
       unsigned char *l_texture;
       int i, j=0;
       FILE *l_file;
       BITMAPFILEHEADER fileheader; 
       BITMAPINFOHEADER infoheader;
       RGBTRIPLE rgb;
       num_texture++;
     
       if( (l_file = fopen(filename, "rb"))==NULL) return (-1);
       fread(&amp;fileheader, sizeof(fileheader), 1, l_file);
       fseek(l_file, sizeof(fileheader), SEEK_SET);
       fread(&amp;infoheader, sizeof(infoheader), 1, l_file);
     
       l_texture = (BYTE *) malloc(infoheader.biWidth * infoheader.biHeight * 4);
       memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * 4);
       glPixelStorei( GL_UNPACK_ALIGNMENT, 1);
     
       for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++)
       { 
          fread(&amp;rgb, sizeof(rgb), 1, l_file); 
     
          l_texture[j+0] = rgb.rgbtRed; // Red component
          l_texture[j+1] = rgb.rgbtRed; // Green component
          l_texture[j+2] = rgb.rgbtBlue; // Blue component
          l_texture[j+3] = 255; // Alpha value
          j += 4; // Go to the next position
       }
       fclose(l_file);
       glBindTexture(GL_TEXTURE_2D, num_texture);
     
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
       glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
       glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
       gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture);
       free(l_texture);
       return num_texture;
     
    }
    You will need the file c:/b.bmp which is on one of the links i sent you in my previous post.

    Thanks again for your help mate

  10. #10
    Senior Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    913

    Re: BMP texture Mapping appears pale

    You have error in code loading the bitmap. You are storing value of red component into value of green component.

    Code :
    l_texture[j+0] = rgb.rgbtRed; // Red component
    l_texture[j+1] = rgb.rgbtRed; // Green component <-- HERE
    l_texture[j+2] = rgb.rgbtBlue; // Blue component

Page 1 of 2 12 LastLast

Similar Threads

  1. nothing appears on the screen
    By hossam in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-05-2016, 12:26 PM
  2. Texture mapping ::: 3D Face Mapping
    By 3render3 in forum OpenGL: General
    Replies: 2
    Last Post: 03-24-2013, 06:49 PM
  3. projective texture mapping and shadow mapping
    By phoenix_gl in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-08-2012, 08:00 PM
  4. Cpw, SOLIDCUBE appears to be a WIRECUBE.
    By jpummill in forum OpenGL: General
    Replies: 2
    Last Post: 02-27-2002, 09:15 AM
  5. Texture Mapping / Environmental Mapping.
    By imported_Andrew in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-09-2000, 01:20 PM

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