OpenGL Texture from Char* Buffer
I'm not sure if anyone here has read Game Coding Complete by Mike McShaffry (it deals with a lot of Win32/DirectX specific issues) but it lays out a solid framework for a game engine using c++. I decided it would be a fun project to (attempt to) port to Mac OS X/OpenGL using mostly c++ with a little obj-c and I have a question:
He uses a resource cache that loads game assets from zip files (using zlib), storing the contents of each individual file (whether it be a .bmp or a .jpeg or a .wav or whatever) in a char* buffer. This is very useful under Windows/DirectX as there is a Direct3D CreateTextureFromMemory() function that takes the char* buffer and spits out a D3D texture.
I'm trying to figure out the best way to go about doing this on a Mac for an OpenGL texture. I tried the following:
From there I could get the CGImageRef in to a texture, but it doesn't seem to be reading the char buffer correctly as my width and height always end up being 0.
Does anyone have any suggestions/ideas? Thanks a lot!
He uses a resource cache that loads game assets from zip files (using zlib), storing the contents of each individual file (whether it be a .bmp or a .jpeg or a .wav or whatever) in a char* buffer. This is very useful under Windows/DirectX as there is a Direct3D CreateTextureFromMemory() function that takes the char* buffer and spits out a D3D texture.
I'm trying to figure out the best way to go about doing this on a Mac for an OpenGL texture. I tried the following:
Code:
CGDataProviderRef pData;
CGImageRef pImage;
const char* textBuffer = texture->Buffer();
size_t textSize = texture->Size();
pData = CGDataProviderCreateWithData(NULL, (char*)textBuffer, textSize, NULL);
pImage = CGImageCreateWithJPEGDataProvider(pData, NULL, false, kCGRenderingIntentDefault);
size_t width = CGImageGetWidth(pImage);
size_t height = CGImageGetHeight(pImage);
std::cout << "Image width: " << width << std::endl;
std::cout << "Image height: " << height << std::endl;From there I could get the CGImageRef in to a texture, but it doesn't seem to be reading the char buffer correctly as my width and height always end up being 0.
Does anyone have any suggestions/ideas? Thanks a lot!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES Texture Compression | ajrs84 | 9 | 476 |
May 7, 2013 03:36 PM Last Post: ajrs84 |
|
| OpenGL Pixel Buffer Object setup issue | dotbianry | 2 | 1,076 |
Jan 6, 2013 11:03 AM Last Post: dotbianry |
|
| OpenGL ES Texture Masking | airfire | 5 | 11,453 |
Nov 14, 2012 09:36 AM Last Post: toanNguyen |
|
| OpenGL ES Texture Masking | dalasjoe sin | 0 | 3,139 |
Apr 13, 2012 12:17 AM Last Post: dalasjoe sin |
|
| Texture in OpenGL ES 2 looks pixelated | vunterslaush | 18 | 17,784 |
Aug 30, 2011 09:44 PM Last Post: Frogblast |
|

