Results 1 to 6 of 6

Thread: 2D Panels

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Chatham, Kent, United Kingdom
    Posts
    7

    2D Panels

    Hi,

    With my OpenGL application how can I load images from the applications resource file and then display them on the screen with OpenGL.

    Another smaller question is how can I draw with the standard GDI in conjunction with OpenGL to remove the flicker.

    Any help would be greatly appreciated!

    Yours Sincerely,
    Lea Hayes

  2. #2

    Re: 2D Panels

    I recall one of Nehe's tutorials at nehe.gamedev.net showing how to use MSVCs resource files for textures. So you may want to check that out.

    Can't help with the other question though, sorry.

    Tina
    Learning OpenGL while working on sourceforge projects:
    https://sourceforge.net/projects/simulant/ and
    https://sourceforge.net/projects/projectnova/

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: 2D Panels

    On the GDI, I think there is a way to do it.
    I think you render to a bitmap, then display it with the GDI.
    But if you are getting flicker, are you using double buffer in your draw routine?
    Also maybe it is how you are drawing your scene. Would have to know more about how you build your scene.


    Originally posted by leahayes00:
    Hi,

    With my OpenGL application how can I load images from the applications resource file and then display them on the screen with OpenGL.

    Another smaller question is how can I draw with the standard GDI in conjunction with OpenGL to remove the flicker.

    Any help would be greatly appreciated!

    Yours Sincerely,
    Lea Hayes

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: 2D Panels

    For loading arbitrary binary resources, you basically do something like so..

    HGLOBAL hResource = LoadResource(hModule, hResInfo);
    void* pData = LockResource(hResource);

    // Access the data for the resource from pData.
    Deiussum
    Software Engineer and OpenGL enthusiast

  5. #5
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Huntsville, AL. USA
    Posts
    302

    Re: 2D Panels

    Sorry, dont have time to explaing it all right now but here is how I do it ...

    Code :
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Load a texture from a resource and return it's index (0 on error); Setup
    // the texture using the following default characteristics:
    // Environment Mode = GL_MODULATE
    // S Wrap Method = GL_REPEAT
    // T Wrap Method = GL_REPEAT
    // Magnification Filter=GL_LINEAR
    // Minification Filter=GL_LINEAR_MIPMAP_LINEAR
    // Perspective Correction Hint = GL_NICEST
     
    size_t MgTextureManager::
    	loadTextureFromResource(
    		unsigned int resourceId,
    		const char* textureName,
    		bool mipMapped
    	)
    {
    	if (!IsOpenGlInitialized())
    	{
    		m_LastErrorDescription =
    			"Attempted to load a texture prior to OpenGL Initialization";
    		return 0;
    	}
     
    	// Load the image;
    	GLuint texIndx(0);
    	glGenTextures(1,&texIndx);
    	if (texIndx==0)
    	{
    		MgString msg(
    			"Failed generating texture OpenGL index for texture named ",
    			textureName
    		);
    		msg << "|" << GetOpenGLErrorMessage();
    		m_LastErrorDescription = msg;
    		return 0;
    	}
     
    	glBindTexture(GL_TEXTURE_2D,texIndx);
    	MgTextureOptions options;
    	options.apply();
     
    	HINSTANCE hInstance;
    	HANDLE hBitmap;
    	BITMAPINFO bmInfo;
    	void *pBitmapData;
     
    	// Find the bitmap resource
    	hInstance = GetModuleHandle(NULL);
    	hBitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(resourceId));
     
    	if (hBitmap == NULL)
    	{
    		m_LastErrorDescription =
    			"Failed loading texture from bitmap resource";
    		return 0;
    	}
    	GetObject(hBitmap,sizeof(BITMAPINFO),&amp;bmInfo);
    	DeleteObject(hBitmap);
     
    	hBitmap =
    		LoadResource(
    			hInstance,
    			::FindResource(hInstance,MAKEINTRESOURCE(resourceId),RT_BITMAP)
    		);
     
    	if (hBitmap == NULL)
    	{
    		m_LastErrorDescription =
    			"Failed finding texture bitmap resource";
    		return 0;
    	}
     
    	pBitmapData = LockResource(hBitmap);
    	int width = bmInfo.bmiHeader.biWidth;
    	int height = bmInfo.bmiHeader.biHeight;
     
    	// This is specific to the binary format of the data read in.
        glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
        glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
        glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
     
    	if (mipMapped)
    	{
    		gluBuild2DMipmaps(
    			GL_TEXTURE_2D,
    			3,
    			width,
    			height,
    			GL_BGR_EXT,
    			GL_UNSIGNED_BYTE,
    			(unsigned char *)pBitmapData+sizeof(bmInfo)+2
    		);
    	}
    	else
    	{
    		glTexImage2D(
    			GL_TEXTURE_2D,
    			0,
    			3,
    			width,
    			height,
    			0,
    			GL_BGR_EXT,
    			GL_UNSIGNED_BYTE,
    			(unsigned char *)pBitmapData+sizeof(bmInfo)+2
    		);
    	}
     
    	TextureInfo info(texIndx,width,height,24);
    	info.options = options;
    	(*p_Textures)[MgStlString(textureName)] = info;
     
    	// Done with bitmap
    	DeleteObject(hBitmap);
     
    	return 0;
    }
    Obsessive - A word used by the lazy to describe the motivated.

  6. #6
    Junior Member Newbie
    Join Date
    Aug 2002
    Location
    Chatham, Kent, United Kingdom
    Posts
    7

    Re: 2D Panels

    Hi,

    Thanks for your help!

    Yours Sincerely,
    Lea Hayes

Similar Threads

  1. Multiple "panels" in one window.
    By Velvet T. Leopard in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 10-06-2017, 02:18 PM
  2. Windows on OpenGL panels are freezing
    By beecksche in forum OpenGL: Windows
    Replies: 1
    Last Post: 02-06-2015, 02:33 AM
  3. which method is best for drawing panels?
    By in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 09-08-2005, 06:23 PM
  4. Drawing a mixture of opaque & translucent panels
    By butcher in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 02-14-2004, 09:24 PM
  5. Two OpenGL panels on single VB form?
    By hopeater in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-22-2000, 08:33 AM

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