Bmp image in a OpenGl window

This is the best I could come up with while trying to display a bmp image in a OpenGL window. It’s not working, so if someone could take a look at it and tell me what’s wrong, I’d be gratefull:


glutInit(&argc, argv);	
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(560,800);
	glutInitWindowPosition(100,100);
	glutCreateWindow("Instrukcja");
	init();
	glutDisplayFunc(display);
	glutMainLoop();


init();


void init(void)
{
	//select clearing (background) color
	glClearColor(0.0, 0.0, 0.0, 0.0);

	//initialize viewing values 
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

}

display();


void display(void)
{
 
	glClear(GL_COLOR_BUFFER_BIT);

	HBITMAP hBmp = (HBITMAP) ::LoadImage (NULL,
                        (LPCTSTR) "Q0.bmp", IMAGE_BITMAP, 0, 0,
 LR_LOADFROMFILE |LR_CREATEDIBSECTION);
	if (hBmp == NULL) {
	printf("Nie znaleziono bitmapy
");
	}
	else printf("Znaleziono bitmape!
");

	BITMAP BM;
	::GetObject (hBmp, sizeof (BM), &BM);
	
        if (BM.bmBitsPixel != 24){
   printf("Zla paleta kolorow!
");
	}
	else   printf("Dobra paleta kolorow!
");


	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
	glDrawPixels( BM.bmHeight, BM.bmWidth, GL_RGB,
GL_UNSIGNED_BYTE, BM.bmBits );
	glEnd();
	
	glFlush();
}

the resulting windo looks like a ‘system halt’ back on the old Win95s. Random configuration of pixels /but the pallete is taken from the desktop/. But at least it’s not black as it was some time ago. So i’m guessing it’s the parameter problem. Can someone help we with finding the right configuration?

Regards, Rafal

i am beginner if mistake please apologies me
you need to create object like Square by glVertex2f
which also have Texture coordinate
seems like
glBegin(GL_QUADS);
glTexCoord2f(x,y);glVertex2f(-x,y);
glTexCoord2f(x,y);glVertex2f(x,-y);
glTexCoord2f(x,y);glVertex2f(-x,y);
glTexCoord2f(x,y);glVertex2f(x,-y);
glEnd();
I suggest you start from beggining
like create object ,transformation etc bla bla bla
caus your init function have mistake
i think you need refrance bas

i tell you in programming language please understand
if(you_care){

cause_you_have_something_like_half_knowladge_and_it_is dangerous_then_an_idiot_so_start_from_beginning
and_come_at_point_of_texture+and_do_this;
}
else
{
damage_your_system_and_reinstall;
}

i want to say that one time i was crazy in programming games but problem is i don’t know how to use opengl(today i also don’t know (beginner)) but that time i wrote source with many mistake which some time take windows xp to blue screen of death
so i just want to give

WARNING YOU: don’t make code which halt start from beginning
so that you don’t face the same problem as i faced

Try DevIl openil.sourceforge.net to load bmp

I finally managed to run the whole thing. If someone is/will be interested, this is my source code for opening a 24 bit bmp from hdd and dosplaying it in a 560x800 window:



void display(void)
{

	glClear(GL_COLOR_BUFFER_BIT);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

	HBITMAP hBmp = (HBITMAP) ::LoadImage (NULL,(LPCTSTR) "Q0.bmp", 
		IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION);
	if (hBmp == NULL) {
	printf("Nie znaleziono bitmapy
");
	}
	else printf("Znaleziono bitmape!
");

	BITMAP BM;
	::GetObject (hBmp, sizeof (BM), &BM);
	  if (BM.bmBitsPixel != 24){
	   printf("Zla paleta kolorow!
");
	  }
	   else
	   printf("Dobra paleta kolorow!
");
		printf("Wysokosc:%d
",BM.bmHeight);
		printf("Szerokosc:%d
",BM.bmWidth);

GLwidth=BM.bmWidth;
GLheight=BM.bmHeight;

	glDrawPixels( GLwidth, GLheight, GL_BGR_EXT, GL_UNSIGNED_BYTE, BM.bmBits );
	glEnd();
	glFlush();
}

void init(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}


main ()
{

int	argc = 1;
char *argv[1] = {{""}};
int g=(int)pvParam;

glutInit(&argc, argv);	
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(560,800);
	glutInitWindowPosition(1400,100);
	glutCreateWindow("Instrukcja sterowania Q0");
	init();
	glutDisplayFunc(display);
	glutMainLoop();

	
 return 0;
}

the ‘main’ name was added just for the show. I was running the opengl window as a new thread so there was no ‘main’ in my code. Originaly /in my code/ there was “FunkcjaWatku(PVOID pvParam)” not “main()”

anyway…

This code creates a opengl window sized 560x 800 and than fills it with a 24bit bmp. The file which one wants to load is to be placed in the same dir as the exe file.

I know I could make a dynamically changing window depending on the image size, but that would require me to get the image data during the init() function, not display. And that would require me to somehow pass the whole image array from the init() function to the display().
If anyone knows how to do it fast and clean, please don’t let me stop you. I’m just not that keen on it. It seemed to me like taking to much from the processor time, but I may be wrong.

If someone does know how to do it, please. Post your response. I’ll be happy to learn something from you.

Regards,
Rafal Typiak

nice!

hmm, i dunno if this is useful, but doesn’t hurt to check:
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06