Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319606
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:50:40+00:00 2026-05-17T22:50:40+00:00

Why are these not displaying the same colors? Original Image: Plane with above Image

  • 0

Why are these not displaying the same colors?

Original Image:

alt text

Plane with above Image as texture:
alt text

WTF is happening?
The original image is 100×100 pixels, made in paint and saved as a 24 bit bitmap.
Here is my opengl initialization code:

    _hdc = GetDC(_hwnd);

PIXELFORMATDESCRIPTOR pfd;
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
int iFormat = ChoosePixelFormat( _hdc, &pfd );
SetPixelFormat( _hdc, iFormat, &pfd );

_hrc = wglCreateContext(_hdc);
wglMakeCurrent(_hdc, _hrc);

GLHelper* helper = GLHelper::get();
helper->initialize(_hwnd, _hdc, _hrc);
changeScreenResolution(_settings.windowWidth, _settings.windowHeight,
    _settings.sceneWidth, _settings.sceneHeight);

// Initialize OpenGL Settings
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_NORMALIZE);
glEnable(GL_TEXTURE_2D);
glDepthFunc(GL_LEQUAL); 
float globalAmbient[4] = {0, 0, 0, 1};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);

I use the library FreeImage, which looks pretty well tested and widely used.

Here is the image loading code:

//image format
FREE_IMAGE_FORMAT fif = FIF_UNKNOWN;
//pointer to the image, once loaded
FIBITMAP *dib(0);
//pointer to the image data
BYTE* bits(0);
//image width and height
unsigned int width(0), height(0);
//OpenGL's image ID to map to
GLuint gl_texID;

//check the file signature and deduce its format
fif = FreeImage_GetFileType(filename, 0);
//if still unknown, try to guess the file format from the file extension
if(fif == FIF_UNKNOWN) 
    fif = FreeImage_GetFIFFromFilename(filename);
//if still unkown, return failure
if(fif == FIF_UNKNOWN)
    return false;

//check that the plugin has reading capabilities and load the file
if(FreeImage_FIFSupportsReading(fif))
    dib = FreeImage_Load(fif, filename);
//if the image failed to load, return failure
if(!dib)
    return false;

//retrieve the image data
bits = FreeImage_GetBits(dib);
//get the image width and height
width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);
//if this somehow one of these failed (they shouldn't), return failure
if((bits == 0) || (width == 0) || (height == 0))
    return false;

//if this texture ID is in use, unload the current texture
if(m_texID.find(texID) != m_texID.end())
    glDeleteTextures(1, &(m_texID[texID]));

//generate an OpenGL texture ID for this texture
glGenTextures(1, &gl_texID);
//store the texture ID mapping
m_texID[texID] = gl_texID;
//bind to the new texture ID
glBindTexture(GL_TEXTURE_2D, gl_texID);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//store the texture data for OpenGL use
glTexImage2D(GL_TEXTURE_2D, level, internal_format, width, height,
    border, image_format, GL_UNSIGNED_BYTE, bits);

//Free FreeImage's copy of the data
FreeImage_Unload(dib);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:50:41+00:00Added an answer on May 17, 2026 at 10:50 pm

    Bitmaps are stored BGR (blue-green-red). Your loading code is loading it as RGB (red-green-blue). This is flipping your red and blue channel.

    Use GL_BGR for the format parameter of glTexImage2D.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to store some data in a Django model. These data are not
I'm not sure if there is a difference in these two methods. If so,
I've tried these, and they did not work (Access opens, but it does not
Each of these variables has an integer value. But this syntax is not valid
Are there O/R mapping tools for ASP (not ASP.NET) and are these useful in
I have seen code around with these two styles , I am not not
apparently it works Can you name reasons beyond good practices not to give these
I've searched, but I've not understood very well these three concepts. When do I
I have some (OpenCV) code that generates images. I'm displaying these using OpenGL. When
I have an image displaying on my website homepage, and I need to place

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.