🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Creating a OpenGL texture from a resorce file

Started by
6 comments, last by Gandalf 24 years ago
Hey, GL Wizards! I need help with creating a OpenGL texture from a bitmap loaded from resoure file.
                                                    

void CreateResTextures()
{
    // bits needed to create a 256x256 24 bits bitmap

    const int iNrBits = 256*256*3;


    // Load bitmap from resource file

    HBITMAP bitmap = LoadBitmap(GetModuleHandle(NULL), 
        MAKEINTRESOURCE(IDB_BITMAP));


    // Allocate bitmap data

    unsigned char *data = new unsigned char[iNrBits];


    // Get bitmap data from handle

    GetBitmapBits(bitmap, iNrBits, data);


    // Create one texture

    glGenTextures(1, &m_texture[0]);


    // Bind name to texture

    glBindTexture(GL_TEXTURE_2D, m_texture[0]);

	
    // Generate the texture

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 
		0, GL_RGB, GL_UNSIGNED_BYTE, data);


   delete data;
}

                                
The pixels in the image is not on correct positions. But I think that all the colors is correct. Only half texture shows up. Somebody of you must have loaded a bitmap from a resource file and used it as a texture Gandalf the White
Edited by - Gandalf on 6/20/00 7:30:12 AM
Gandalf the Black
Advertisement
I''m sorry not to be able to answer you question, but how do you do this cool IDE-like code formatting ? Do you use any special proggie or type everything by hand ? It is so... clear !

EL
----------------------------------------"Inash neteia haeg joa kavari quilm..." SD4
    You make the IDE - like code windows with [ source ] (don''t write the spaces)    


Visit our homepage: www.rarebyte.de.st

GA
Visit our homepage: www.rarebyte.de.stGA
I''m using 24bits uncompressed 256x256 TGA images.
Maybe a bit big...but compression is a thing of the last minute.
And it''s very easy to use, no loss of data...

Anyway here''s the source:
    	PIXEL Texture[256*256];	typedef struct	{	char	CompressionHeader[12];		WORD	Width;		WORD	Height;		WORD	BitsPerPixel;		unsigned char Data[1];	}	TGAHEADER, *PTGAHEADER;	void *pResTexture = LockResource(LoadResource(NULL, FindResource(NULL, MAKEINTRESOURCE(IDT_TEXTURE), "TGA")));	unsigned char *pTexture = ((PTGAHEADER)pResTexture)->Data;	for(int j=0; j<256; j++)	for(int i=0; i<256; i++)	{	Texture[(255-j)*256 + i].b = *pTexture++;		Texture[(255-j)*256 + i].g = *pTexture++;		Texture[(255-j)*256 + i].r = *pTexture++;	}	glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, Texture);    


Thank you very much!

But I have 2 questions for you:

1. PIXEL? What lib and header is needed to find this structure?
2. Can Paintshop save TGA files?

Gandalf the White

Gandalf the Black
Sorry, only a try

    #include<stdio.h>void main(){   printf("Hello, world!\n");}    


Does it work ?

How to close the source tag ?

Are you sure the texture coordinates are correct ?
(you can find me on IRC : #opengl on undernet)
Yes I am, and that problem is already solved now.
Thanks anyway.

Gandalf the White

Gandalf the Black

This topic is closed to new replies.

Advertisement