Exemplo n.º 1
0
bool Window::renderFrame()
{
    // Update time
    timeSinceLastFrame = glfwGetTime() - lastFrameTime;
    lastFrameTime = glfwGetTime();

    // Clear Screen
    // TODO: Add clearing depth buffer when it is necessary
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Call assigned render function
    renderFunction(timeSinceLastFrame);

    // Poll inputs
    glfwPollEvents();

    // Update view matrix
    Program::updateViewMatrix(Camera::getCurrentCamera()->getViewMatrix());

    // Swap Buffers -- Always do this at the end of frame's render
    glfwSwapBuffers(window);

    // Determine if window should close
    // TODO: Move key functionality to input callback
    bool shouldClose = shouldClose || glfwWindowShouldClose(window);

    return !shouldClose;
}
Exemplo n.º 2
0
void DrawWaveform::
        draw_glList( boost::shared_ptr<RenderData> chunk, void (*renderFunction)( boost::shared_ptr<RenderData> ), bool force_redraw )
{
#ifdef LEGACY_OPENGL
    // do a cache lookup
    std::map<void*, ListCounter>::iterator itr = _chunkGlList.find(chunk.get());

    if (_chunkGlList.end() == itr && force_redraw) {
        force_redraw = false;
    }

    // cache miss or force_redraw
    if (_chunkGlList.end() == itr || force_redraw) {
        ListCounter cnt;
        if (force_redraw) {
            cnt = itr->second;
            cnt.age = ListCounter::Age_InUse;
        } else {
            cnt.age = ListCounter::Age_JustCreated;
            cnt.displayList = glGenLists(1);
        }

        if (0 != cnt.displayList) {
            glNewList(cnt.displayList, GL_COMPILE_AND_EXECUTE );
            renderFunction( chunk );
            glEndList();
            _chunkGlList[chunk.get()] = cnt;

        } else {
            // render anyway, but not into display list and enqueue gc
            _enqueueGcDisplayList = true;
            renderFunction( chunk );
        }

    } else {
        // render cache
        itr->second.age = ListCounter::Age_InUse; // don't remove

        glCallList( itr->second.displayList );
    }
#else
    EXCEPTION_ASSERTX(false, "requires LEGACY_OPENGL");
#endif
}
Exemplo n.º 3
0
void GLCanvas::keyboard(unsigned char key, int x, int y) {
	switch (key) {
	case 'r':  // 'R' = call the render routine
	case 'R':
		printf("Beginning scene render...\n");
		if (renderFunction) renderFunction(scene);
		printf("   ...done.\n");
		break;
	}
}
Exemplo n.º 4
0
int main(int argc, char* argv[])
{
	// sample command line:
	// raytracer -input scene1_1.txt -size 200 200 -output output1_1.tga -depth 9 10 depth1_1.tga
	for (int i = 1; i < argc; i++) {
		if (!strcmp(argv[i], "-input")) {
			i++; assert(i < argc);
			input_file = argv[i];
		}
		else if (!strcmp(argv[i], "-size")) {
			i++; assert(i < argc);
			width = atoi(argv[i]);
			i++; assert(i < argc);
			height = atoi(argv[i]);
		}
		else if (!strcmp(argv[i], "-output")) {
			i++; assert(i < argc);
			output_file = argv[i];
		}
		else if (!strcmp(argv[i], "-depth")) {
			i++; assert(i < argc);
			depth_min = atof(argv[i]);
			i++; assert(i < argc);
			depth_max = atof(argv[i]);
			i++; assert(i < argc);
			depth_file = argv[i];
		}
		else if (!strcmp(argv[i], "-normals")){
			i++; assert(i < argc);
			normal_file = argv[i];
		}
		else if (!strcmp(argv[i], "-gui")){
			gui = true;
		}
		else if (!strcmp(argv[i], "-tessellation")){
			i++; assert(i < argc);
			theta = atoi(argv[i]);
			i++; assert(i < argc);
			phi = atoi(argv[i]);
		}
		else if (!strcmp(argv[i], "-gouraud")){
			gouraud_flag = true;
		}
		else if (!strcmp(argv[i], "-shadows")){
			shadow = true;
		}
		else if (!strcmp(argv[i], "-bounces")){
			i++; assert(i < argc);
			max_bounces = atoi(argv[i]);
		}
		else if (!strcmp(argv[i], "-weight")){
			i++; assert(i < argc);
			weight = atof(argv[i]);
		}
		else if (!strcmp(argv[i], "-shade_back")){
			
		}
		else {
			printf("whoops error with command line argument %d: '%s'\n", i, argv[i]);
			assert(0);
		}
	}
	//Use the input file parsing code provided to load the camera, 
	//background color and objects of the scene.
	sceneParser = new SceneParser(input_file);
	rayTracer = new RayTracer(sceneParser,max_bounces,weight,shadow);
	RayTree *rayTree = new RayTree();
	if (gui){
		GLCanvas* glCanvas = new GLCanvas();
		//renderFunction:渲染函数,直接绘制出图像
		//traceRayRunction:光线跟踪函数,预览图中绘制光线路径
		glCanvas->initialize(sceneParser, renderFunction, traceRayFunction);
	}
	else{
		renderFunction();
	}
	
	return 0;
}
Exemplo n.º 5
0
/* Will call render function and then glutPosRedisplay() */
static void
do_glut_display() {
	if (renderFunction) renderFunction();
	glutPostRedisplay();
}