Skip to content

Instantly share code, notes, and snippets.

@satoruhiga
Created October 19, 2011 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satoruhiga/1298938 to your computer and use it in GitHub Desktop.
Save satoruhiga/1298938 to your computer and use it in GitHub Desktop.
Multithreaded image loading
#include "testApp.h"
static CGLContextObj ctx;
static CGLPixelFormatObj pixStuff;
class MyThread : public ofThread
{
public:
ofImage image;
void threadedFunction()
{
printf("start\n");
CGLContextObj newCtx;
CGLCreateContext(pixStuff, ctx, &newCtx);
CGLLockContext(newCtx);
CGLSetCurrentContext(newCtx);
CGLEnable(newCtx, kCGLCEMPEngine);
image.loadImage("http://forum.openframeworks.cc/Themes/ofw-theme/images/site/banner.gif");
CGLDisable(newCtx, kCGLCEMPEngine);
CGLUnlockContext(newCtx);
CGLDestroyContext(newCtx);
printf("stop\n");
}
};
MyThread thread;
//--------------------------------------------------------------
void testApp::setup()
{
ofSetFrameRate(60);
ofSetVerticalSync(true);
ctx = CGLGetCurrentContext();
pixStuff = CGLGetPixelFormat(ctx);
thread.startThread(true, false);
}
//--------------------------------------------------------------
void testApp::draw()
{
ofDrawBitmapString(ofToString(ofGetFrameRate(), 2), 10, 20);
thread.image.draw(0, 30);
}
//--------------------------------------------------------------
void testApp::keyPressed(int key)
{
}
//--------------------------------------------------------------
void testApp::keyReleased(int key)
{
}
//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y)
{
}
//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::mouseReleased(int x, int y, int button)
{
}
//--------------------------------------------------------------
void testApp::windowResized(int w, int h)
{
}
//--------------------------------------------------------------
void testApp::gotMessage(ofMessage msg)
{
}
//--------------------------------------------------------------
void testApp::dragEvent(ofDragInfo dragInfo)
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment