Пример #1
0
    virtual void on_ctrl_change()
    {
        if(m_benchmark.status())
        {
            int i;
            on_draw();
            update_window();

            scanline_rasterizer ras;

            pixfmt pixf(rbuf_window());
            base_renderer rb(pixf);
            solid_renderer solid(rb);
            draft_renderer draft(rb);

            char buf[256];
            if(m_draft.status())
            {
                start_timer();
                for(i = 0; i < 10; i++)
                {
                    draw_scene(ras, solid, draft);
                }
                sprintf(buf, "%3.3f milliseconds", elapsed_time());
            }
            else
            {
                double times[5];
                for(m_draw = 0; m_draw < 4; m_draw++)
                {
                    start_timer();
                    for(i = 0; i < 10; i++)
                    {
                        draw_scene(ras, solid, draft);
                    }
                    times[m_draw] = elapsed_time();
                }
                m_draw = 3;

                times[4]  = times[3];
                times[3] -= times[2];
                times[2] -= times[1];
                times[1] -= times[0];
            
                FILE* fd = fopen(full_file_name("benchmark"), "a");
                fprintf(fd, "%10.3f %10.3f %10.3f %10.3f %10.3f\n", 
                            times[0], times[1], times[2], times[3], times[4]);
                fclose(fd);
            

                sprintf(buf, "  pipeline  add_path         sort       render       total\n"
                             "%10.3f %10.3f %10.3f %10.3f %10.3f", 
                        times[0], times[1], times[2], times[3], times[4]);
            }
            message(buf);

            m_benchmark.status(false);
            force_redraw();
        }
    }
Пример #2
0
void viewport_draw(t_viewport *viewport)
{
	t_context *C = ctx_get();

	op_3d_orientation(); 
	draw_scene(C->draw,C->scene);
}
Пример #3
0
/*
 * Run through one frame drawing cycle
 */
void SdlApp::step()
{
	if (!running) return;

	draw_scene();

	SDL_Event event;
	while ( SDL_PollEvent( &event ) )
	{
		switch( event.type )
		{
			case SDL_ACTIVEEVENT:
				//TODO: handle focus change
				break;			    
			case SDL_KEYDOWN:
				/* handle key presses */
				handle_key_press( &event.key.keysym );
				break;
			case SDL_QUIT:
				/* handle quit requests */
				tear_down();
				break;
			default:
				break;
		}
	}

}
Пример #4
0
void display_view(int const win_width, int const win_height)
{
	float const win_aspect = (float)win_width / (float)win_height;
	frustum.left = -(frustum.right = win_aspect);

	glViewport(0, 0, win_width, win_height);
	glClearColor(0.3, 0.3, 0.6, 1.);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(
		frustum.left,
		frustum.right,
		frustum.bottom,
		frustum.top,
		frustum.near,
		frustum.far );
	
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_DEPTH_TEST);

#if OPTION_MULTISAMPLE
	glEnable(GL_MULTISAMPLE);
#endif

	draw_scene();

	glutSwapBuffers();
}
Пример #5
0
void draw(void)
{
  GLenum err;
  GLfloat secs = get_secs();
  
  glDisable(GL_STENCIL_TEST);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  
  if (!headsUp) glEnable(GL_STENCIL_TEST);
  draw_scene(secs, draw_passes, GL_BACK, 0, (unsigned)-1);
  glDisable(GL_STENCIL_TEST);

  if (headsUp) {
    /* draw a red floor on the original scene */
    glDisable(GL_LIGHTING);
    glBegin(GL_QUADS);
    glColor3f(1, 0, 0);
    glVertex3f(-1, -.95, 1);
    glVertex3f(1, -.95, 1);
    glVertex3f(1, -.95, -1);
    glVertex3f(-1, -.95, -1);    
    glEnd();
    glEnable(GL_LIGHTING);
  }

  err = glGetError();
  if (err != GL_NO_ERROR) printf("Error:  %s\n", gluErrorString(err));
  
  glutSwapBuffers(); 
}
Пример #6
0
/// main draw method
void display() {
    hud_fps_display.start();
    if(draw_opts.cameralights) scene_cameralights_update(scene,draw_opts.cameralights_dir,draw_opts.cameralights_col);
    draw_scene(scene,draw_opts,true);
    draw_scene_decorations(scene,draw_opts,false);
    glFlush();
    hud_fps_display.stop();
    
    if(selected_frame) {
        auto axes = Axes();
        axes.frame = *selected_frame;
        draw_gizmo(&axes);
        if(selected_point) {
            auto dot = Dot();
            dot.pos = transform_point(*selected_frame, *selected_point);
            draw_gizmo(&dot);
        }
    }
    
    if(hud) display_hud();
    
    glutSwapBuffers();
    
    if(screenshotAndExit) {
        if(time_init_advance <= 0.0f or draw_opts.time >= time_init_advance ) {
            screenshot(filename_image.c_str());
            exit(0);
        }
    }
}
Пример #7
0
void
display(void)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  draw_scene();

  glutSwapBuffers();
}
Пример #8
0
void display()						// main display routine
{
  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  draw_scene();  
  glFlush();
  glutSwapBuffers();
}
Пример #9
0
void
GLUTCALLBACK my_display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);

    draw_scene();

    glutSwapBuffers();
}
Пример #10
0
Файл: o6.c Проект: manish05/TCR
/* Program entry point */
int main (int argc, char* argv[]) {
   debug=fopen("debug.txt","w");

    // window dimensions
    int width  = 640;
    int height = 480;
    const SDL_VideoInfo *info;

    /* initialize SDL's video subsystem */
    if (SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0) {
        fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    /* retrieve video information */
    info = SDL_GetVideoInfo( );
    if (!info) {
        fprintf( stderr, "Video query failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,   8 ); /* min 8bit red */
    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8 ); /* min 8bit green */
    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,  8 ); /* min 8bit blue */
    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); /* 16bit depth buffer */
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); /* require double buffering */

    /* Set video mode */
    SDL_Surface * surface = SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, SDL_OPENGL);
    if (!surface) {
        fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
        return -1;
    }

    /* OpenGL initialization */
    setup_opengl(width, height);

    init();
    lys();
    tekstur();

    /* main event loop */
    while (running) {
      animer();
        /* Process incoming events */
        process_events();
        /* Draw the screen */
        draw_scene();

      sprett();
        SDL_Delay(1000/500); /* limit to 5fps */
    }

    SDL_Quit(); /* unload SDL */
    fclose(debug);
    return 0;
}
Пример #11
0
void 
TrackballViewer::
display()
{
	draw_scene(draw_mode_);	
	
	// switch back-buffer to front-buffer
	glutSwapBuffers();
}
Пример #12
0
static int nebulus_draw (NebulusPrivate *priv, VisVideo *video)
{
	draw_scene ();
	glFinish ();

	nebulus_calc_fps (priv);

	return 0;
}
Пример #13
0
static void display()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    draw_scene();

    glutSwapBuffers();
}
Пример #14
0
void display() {
	glClearColor(0,0,0.3,1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
		glRotatef(y_rot,0,1,0);
		draw_scene();
	glPopMatrix();

	glutSwapBuffers();
}
Пример #15
0
void idle()
{
  //hack to make it only draw once
  static int once=0;
  if(!once)
  {
      draw_scene();
      if(mode == MODE_JPEG)
	save_jpg();
    }
  once=1;
}
Пример #16
0
/* draw the user object */
static int  draw_object(int obj_id, double gl_para[16])
{
	GLfloat   mat_ambient[] = { 0.0, 0.0, 1.0, 1.0 };
	GLfloat   mat_ambient_collide[] = { 1.0, 0.0, 0.0, 1.0 };
	GLfloat   mat_flash[] = { 0.0, 0.0, 1.0, 1.0 };
	GLfloat   mat_flash_collide[] = { 1.0, 0.0, 0.0, 1.0 };
	GLfloat   mat_flash_shiny[] = { 50.0 };
	GLfloat   light_position[] = { 100.0, -200.0, 200.0, 0.0 };
	GLfloat   ambi[] = { 0.1, 0.1, 0.1, 0.1 };
	GLfloat   lightZeroColor[] = { 0.9, 0.9, 0.9, 0.1 };

	argDrawMode3D();
	argDraw3dCamera(0, 0);
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixd(gl_para);

	/* set the material */
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);
	glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
	glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);

	glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);

	switch (obj_id){
	case 0:
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glColor3f(1.0, 2.0, 0.0);

		//glTranslated(10.0, 20.0, -100.0);
		draw_scene();
		//glTranslated(-10.0, -20.0, 100.0);
		break;
	case 1:
		glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
		glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
		glColor3f(1.0, 0.0, 0.0);
		//draw piano left
			break;
	case 2:
		
			glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
			glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
			glColor3f(1.0, 2.0, 0.0);
			draw_controller(distX/4, distY/4);
		break;
		}
		argDrawMode2D();

		return 0;
	}
Пример #17
0
    void onOnceBeforeDraw() override {
        SkPictureRecorder recorder;
        SkCanvas* pictureCanvas = recorder.beginRecording(kPictureSize, kPictureSize);
        draw_scene(pictureCanvas, kPictureSize);
        SkAutoTUnref<SkPicture> picture(recorder.endRecording());

        SkPoint offset = SkPoint::Make(100, 100);
        pictureCanvas = recorder.beginRecording(SkRect::MakeXYWH(offset.x(), offset.y(),
                                                                 kPictureSize, kPictureSize));
        pictureCanvas->translate(offset.x(), offset.y());
        draw_scene(pictureCanvas, kPictureSize);
        SkAutoTUnref<SkPicture> offsetPicture(recorder.endRecording());

        for (unsigned i = 0; i < SK_ARRAY_COUNT(tiles); ++i) {
            SkRect tile = SkRect::MakeXYWH(tiles[i].x * kPictureSize,
                                           tiles[i].y * kPictureSize,
                                           tiles[i].w * kPictureSize,
                                           tiles[i].h * kPictureSize);
            SkMatrix localMatrix;
            localMatrix.setTranslate(tiles[i].offsetX * kPictureSize,
                                     tiles[i].offsetY * kPictureSize);
            localMatrix.postScale(kFillSize / (2 * kPictureSize),
                                  kFillSize / (2 * kPictureSize));

            SkPicture* picturePtr = picture.get();
            SkRect* tilePtr = &tile;

            if (tile == SkRect::MakeWH(kPictureSize, kPictureSize)) {
                // When the tile == picture bounds, exercise the picture + offset path.
                picturePtr = offsetPicture.get();
                tilePtr = NULL;
            }

            fShaders[i].reset(SkShader::CreatePictureShader(picturePtr,
                                                            SkShader::kRepeat_TileMode,
                                                            SkShader::kRepeat_TileMode,
                                                            &localMatrix,
                                                            tilePtr));
        }
    }
Пример #18
0
void display() {
	glClearColor(0,0.6,0.7,1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
		glRotatef(x_rot,1,0,0);
		glRotatef(y_rot,0,1,0);
		glLightfv(GL_LIGHT0,GL_POSITION,dir_position);
		draw_scene();
	glPopMatrix();

	glutSwapBuffers();
}
Пример #19
0
//---------------------------------------------------------------------------
void emberManager::update()
{
	processInput();
	// 绘制合适的场景
	if( isFight )
	{
		drawFightScene( ember, evil );
		isFight = false;
	}
	else
	{
		draw_scene();
	}
}
Пример #20
0
void templateAppDraw( void ) {

	glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );

	GFX_set_matrix_mode( PROJECTION_MATRIX );
	GFX_load_identity();
	
	GFX_set_perspective( 45.0f,
						 ( float )viewport_matrix[ 2 ] / ( float )viewport_matrix[ 3 ],
						 0.1f,
						 100.0f,
						 -90.0f );
	
	draw_scene();
}
Пример #21
0
void Window::displayPikachu(void){
    clock_t startTime = clock();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // clear color and depth buffers

    t += 0.01;
    if(t >= number_of_curves){
        t = 1.01;
    }
    draw_scene();
    glFlush();
    glutSwapBuffers();
    glColor4f(1, 1, 1, 1);
    clock_t endTime = clock();
    cout << "frame rate: " << 1.0/(float((endTime - startTime))/CLOCKS_PER_SEC) << endl;
}
Пример #22
0
void
GLView::draw(PaintDC& dc)
{
	if(m_rc == NULL) return;

	wglMakeCurrent(*m_dc, m_rc);

//	glPushMatrix();
	draw_scene();
//	glPopMatrix();

	glFinish();

	if(flags() & DOUBLE_BUFFERING)
		SwapBuffers(dc);
}
Пример #23
0
int
main(int argc, char *argv[]) {
	int ret, nglyphs;
	SDL_Window *window;
	SDL_Renderer *renderer;
	Scene scene;
	Glyph glyphs[NGLYPHS];
	FILE *source;
	
	/* Initialize the TTF library */
	if (TTF_Init() < 0) {
		fprintf(stderr, "Couldn't initialize TTF: %s\n",SDL_GetError());
		SDL_Quit();
		exit(2);
	}

	if (argc == 1)
		nglyphs = read_source(stdin, glyphs, NGLYPHS);
	else {
		source = fopen(argv[1], "r");
		if (source == NULL) {
			fprintf(stderr, "Cannot open file: %s\n", argv[1]);
			cleanup(2);
		}
		nglyphs = read_source(source, glyphs, NGLYPHS);
		fclose(source);
	}
	load_fonts();
	if (SDL_CreateWindowAndRenderer(WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer) < 0) {
		fprintf(stderr, "SDL_CreateWindowAndRenderer() failed: %s\n", SDL_GetError());
		cleanup(2);
	}

	ret = render_text(renderer, &scene, glyphs, nglyphs);
	if (ret > 0) {
		close_fonts();
		cleanup(ret);
	}
	draw_scene(renderer, &scene);
	
	ret = scene_loop(renderer, &scene);
	close_fonts();
	cleanup(ret);
	
	return 0;
}
Пример #24
0
int main(int argc, char *argv[])
{
    const fixed dt = (1 << FIXPOINT_SHIFT) / 100;   // 60 FPS
    fixed t = 0;
    fixed accumulator = 0;
    fixed delta_time = 0;
    SDL_Event event;

    init();

    while (!app.quit)
    {
        start_frame();

        delta_time = get_last_frame_time();

        if (SDL_PollEvent(&event))
        {
            handle_event(&event);
        }

        if (!app.paused)
        {
            accumulator += delta_time;
//            trace("accumulator %ld, dt: %ld, delta_time %ld", accumulator, dt, delta_time);

            while (accumulator >= dt)
            {
                move_objects(t, dt);
                t += dt;
                accumulator -= dt;
            }

            interpolate(fpdiv(accumulator, dt));

            draw_scene();
        }

        end_frame();
    }

    return 0;
}
Пример #25
0
int main(int argc, char *argv[])
{
	initialize();
	fileout << "Initialization complete." << endl << flush;
	Menu::main();
	
	if (menu_quit == false)
	{
		//SDL_ShowCursor(SDL_DISABLE);
		//SDL_WM_GrabInput(SDL_GRAB_ON);
		draw_scene();
		
		event_loop();
		fileout << endl << "Event loop finished." << endl << flush;
    }
    SDL_Quit();
	fileout << "Cleanup complete." << endl << flush;
    return 0;
}
Пример #26
0
int main()
{
	BOOL quit = FALSE;
	SDL_Event event;
	
	init();	
	while (!quit) {
		while ( SDL_PollEvent(&event)) {

			if (event.type == SDL_QUIT) {
				quit = TRUE;
			}
		}
		draw_scene();
		SDL_GL_SwapBuffers();
		SDL_Delay(10);
	}
	SDL_Quit();
	return 0;
}
Пример #27
0
void TextDisplay::main_display_loop() {
  // Display a generic welcome message:
  cout << "Welcome to PlayToLearn text adventure!" << endl;
  cout << "--------------------------------------" << endl;
  draw_scene();
  
  while (true) {
    // Pull the next interaction data and see if we should continue:
    InteractionPrompt::Ptr interaction_data = request_interaction(Util::kDefaultObject);
    if (!interaction_data) break;
    
    display_interaction_prompt(interaction_data);
    Interaction::Ptr interaction = handle_interaction(interaction_data);
    if (interaction) {
      string response = register_interaction(interaction);
      if (!response.empty())
        cout << response << endl;
    }
  }
}
Пример #28
0
    //------------------------------------------------------------------------
    virtual void on_draw()
    {
        scanline_rasterizer ras;

        pixfmt pixf(rbuf_window());
        base_renderer rb(pixf);
        solid_renderer solid(rb);
        draft_renderer draft(rb);

        rb.clear(agg::rgba(1, 1, 1));
        draw_scene(ras, solid, draft);

        ras.filling_rule(agg::fill_non_zero);
        agg::render_ctrl(ras, m_sl, rb, m_type);
        agg::render_ctrl(ras, m_sl, rb, m_width);
        agg::render_ctrl(ras, m_sl, rb, m_benchmark);
        agg::render_ctrl(ras, m_sl, rb, m_draw_nodes);
        agg::render_ctrl(ras, m_sl, rb, m_draw_edges);
        agg::render_ctrl(ras, m_sl, rb, m_draft);
        agg::render_ctrl(ras, m_sl, rb, m_translucent);
    }
Пример #29
0
void
main_loop (std::vector<Mosquito>& _swarm, Dragonfly& _dragonfly)
{
	is_active = true;
	SDL_Event event;

	while (!done)
	{
		while (SDL_PollEvent(&event))
		{
			switch (event.type)
			{
				case SDL_ACTIVEEVENT:
					if (event.active.state == SDL_APPACTIVE )
						is_active = (event.active.gain != 0);
				break;

				case SDL_QUIT:
					done = true; 
				break;

				default:
				break;
			}
		}

			
		if (is_active)
		{
			_swarm = step(_swarm, _dragonfly);
			_dragonfly.velocity += hunt(_dragonfly, _swarm);
			if (_dragonfly.velocity.length() > 0.2)
				_dragonfly.velocity /= 10.0f;
			_dragonfly.position += _dragonfly.velocity;

			draw_scene(_swarm, _dragonfly);
			SDL_GL_SwapBuffers();
		}
	}
}
Пример #30
0
//------------------------------------------------------------------------------
void Frame::draw() {
  if (!valid()) {
    glClearColor(0.0, 0.0, 0.0, 1);                        // Turn the background color black
    glViewport(0,0,w(),h());                               // Make our viewport the whole window
    glMatrixMode(GL_PROJECTION);                           // Select The Projection Matrix
    glLoadIdentity();                                      // Reset The Projection Matrix
    gluOrtho2D(framexmin,framexmax,frameymin,frameymax);                             // (xmin,xmax,ymin,ymax)
    //gluPerspective(45.0f,w()/h(), 1 ,150.0);
    glMatrixMode(GL_MODELVIEW);                            // Select The Modelview Matrix
    glLoadIdentity();                                      // Reset The Modelview Matrix
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                      // Reset The View
    //gluLookAt( 0, 0, 10,     0, 0, 0,     0, 1, 0);         // Position - View  - Up Vector
    glEnable(GL_DEPTH_TEST);
    
	  
    valid(1);
  }
	
	if(newgraph==1){draw_init(); newgraph=0;}

  draw_scene();
}