OpenGL Texture from Char* Buffer

Posts: 11
Joined: 2007.04
Post: #1
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:

    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!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Masking airfire 6 23,208 Mar 17, 2014 07:07 PM
Last Post: baioses
  OpenGL ES Texture Compression ajrs84 9 11,595 May 7, 2013 03:36 PM
Last Post: ajrs84
  OpenGL Pixel Buffer Object setup issue dotbianry 2 6,347 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  OpenGL ES Texture Masking dalasjoe sin 0 5,347 Apr 13, 2012 12:17 AM
Last Post: dalasjoe sin
  Texture in OpenGL ES 2 looks pixelated vunterslaush 18 39,369 Aug 30, 2011 09:44 PM
Last Post: Frogblast