I am using a library at http://partow.net/programming/bitmap/index.html and OpenGL to make a function to load a bitmap on my screen. the image loads but it only displays black, white, and yellow. I am using Dev C++ on Windows 7. Here is my code:
void Load_Image(HDC hDC, string File_Name, int x_position, int y_position, int length, int height)
{
bitmap_image image(File_Name); // Open the bitmap
unsigned char red;
unsigned char green;
unsigned char blue;
restart:
image.get_pixel(x_position, y_position, red, green, blue); // Get the red green and blue from x_position and y_position and store it in red green and blue.
glBegin (GL_TRIANGLES); // Make a pixel at x_position and y_position with red green and blue.
glColor3f (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glEnd();
glBegin (GL_TRIANGLES);
glColor3f (red, green, blue);
glVertex2f (-1 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 1 - 0.003 * y_position);
glVertex2f (-0.9985 + 0.0015 * x_position, 0.997 - 0.003 * y_position);
glEnd();
if (x_position==length) // If x_position equals to length of bmp set x_position to 0 and add 1 to y_position.
{
if (y_position==height) // If bmp is done loading go to done.
{
goto done;
}
x_position = 0;
y_position = y_position + 1;
}
x_position = x_position + 1;
goto restart;
done:
SwapBuffers(hDC); // Put it on the screen.
}
Any ideas on what's wrong? Thanks!
The color values red
, green
, blue
are of type unsigned char
and in the range 0..255. The floating point variant of glColor
, glColor3f
however expects input values in the range 0..1. Try using glColor3ub()
instead.
UPDATED: My original answer suggested glColor3b()
but it should be the unsigned variant glColor3ub()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With