Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Bmp image in a OpenGl window

  1. #1
    Junior Member Newbie
    Join Date
    May 2009
    Posts
    6

    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:

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

    init();

    Code :
    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();

    Code :
    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\n");
    	}
    	else printf("Znaleziono bitmape!\n");
     
    	BITMAP BM;
    	::GetObject (hBmp, sizeof (BM), &BM);
     
            if (BM.bmBitsPixel != 24){
       printf("Zla paleta kolorow!\n");
    	}
    	else   printf("Dobra paleta kolorow!\n");
     
     
    	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

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Re: Bmp image in a OpenGl window

    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
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Re: Bmp image in a OpenGl window

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

    cause_you_have_something_like_half_knowladge_and_i t_is dangerous_then_an_idiot_so_start_from_beginning
    and_come_at_point_of_texture+and_do_this;
    }
    else
    {
    damage_your_system_and_reinstall;
    }
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Re: Bmp image in a OpenGl window

    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


    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  5. #5
    Junior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    185

    Re: Bmp image in a OpenGl window

    Try DevIl openil.sourceforge.net to load bmp
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  6. #6
    Junior Member Newbie
    Join Date
    May 2009
    Posts
    6

    Re: Bmp image in a OpenGl window

    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:

    Code :
     
    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\n");
    	}
    	else printf("Znaleziono bitmape!\n");
     
    	BITMAP BM;
    	::GetObject (hBmp, sizeof (BM), &amp;BM);
    	  if (BM.bmBitsPixel != 24){
    	   printf("Zla paleta kolorow!\n");
    	  }
    	   else
    	   printf("Dobra paleta kolorow!\n");
    		printf("Wysokosc:%d\n",BM.bmHeight);
    		printf("Szerokosc:%d\n",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(&amp;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

  7. #7
    Junior Member Newbie
    Join Date
    May 2009
    Location
    Netherlands
    Posts
    14

    Re: Bmp image in a OpenGl window

    nice!

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •