#include #include #include #include #include GLuint g_texId = 0; void render(void); void createEnvironment(void); void resize(int,int); void handleIdle(void); int main(int argc,char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("SeeFront Demo"); glutReshapeWindow(1920,1080); glutDisplayFunc(render); glutReshapeFunc(resize); glutIdleFunc(handleIdle); createEnvironment(); glutMainLoop(); return(0); } /* * Initialize OpenGL and SeeFront */ void createEnvironment(void) { // OpenGL init glEnable(GL_DEPTH_TEST); glDisable(GL_LINE_SMOOTH); glDisable(GL_POINT_SMOOTH); glDisable(GL_DITHER); glDisable(GL_CULL_FACE); glBindTexture(GL_TEXTURE_2D, g_texId); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1920, 1080, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); } /* * The render method. * Here the scene is rendered two times. One for the left eye and one for the right eye. * The rendered scene is copied into the textures and passed to the SeeFront object. */ void render(void) { glClearColor(255, 0, 0, 255); glClear(GL_COLOR_BUFFER_BIT); unsigned char* buffer = new unsigned char[1920*1080*4]; int mem; glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &mem); boost::chrono::steady_clock::time_point tpStart = boost::chrono::steady_clock::now(); glBindTexture(GL_TEXTURE_2D, g_texId); glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 1920, 1080, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glBindTexture(GL_TEXTURE_2D, 0); glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &mem); boost::chrono::steady_clock::time_point tpEnd = boost::chrono::steady_clock::now(); boost::chrono::milliseconds dur = boost::chrono::duration_cast(tpEnd - tpStart); int msec = static_cast(dur.count()); std::stringstream numberString; numberString << msec; std::cout << numberString.str() << std::endl; delete buffer; glutSwapBuffers(); } void handleIdle(void) { glutPostRedisplay(); } void resize(int w,int h) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0,0,(GLsizei)w,(GLsizei)h); }