Created
October 19, 2011 16:58
-
-
Save satoruhiga/1298938 to your computer and use it in GitHub Desktop.
Multithreaded image loading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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