• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TIMER类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中TIMER的典型用法代码示例。如果您正苦于以下问题:C++ TIMER类的具体用法?C++ TIMER怎么用?C++ TIMER使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了TIMER类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: VFIO

VFIO(timer_write, file, data, size)
{
        TIMER *timer = (TIMER*)data;
        unsigned char cnf = 1, i = 1;
        timer->config = timer->config & 0x7;
        while(timer->config)
        {
                cnf &= timer->config;
                switch(cnf)
                {
                        case 0x4:
                                timer->set_mode(timer);
                                break;
                        case 0x2:
                                timer->set_frq(timer);
                                break;
                        case 0x1:
                                /* get the tick offset */
                                if(size <= sizeof(void*))
                                        return 0;
                                uint64_t offset = *((uint64_t*)(data+
                                                                sizeof(void*)));
                                timer->set_tick(timer, offset);
                                break;

                        default: /* unknown config word.. reset bits set? */
                                break;
                }
                timer->config &= (~cnf); /* disable just checked bit */
                cnf = (++i)<<1;
                if(cnf >= 1>>3)
                        break;
        }
        return E_SUCCESS;
}
开发者ID:Orion-Community,项目名称:andromeda,代码行数:35,代码来源:timer.c


示例2: IRQ

IRQ(timer_irq, irq, stack)
{
        struct irq_data *data = get_irq_data(irq);
        struct device *dev = (struct device *)(data->irq_data);

        TIMER *timer = dev->device_data;
        timer->tick++;
        timer->tick_handle(timer);

        return;
}
开发者ID:Orion-Community,项目名称:andromeda,代码行数:11,代码来源:timer.c


示例3:

void LocalClient::KeystateTaskThread::task() {
	
	#define KEYSTATE_GRANULARITY_MS 46.66	// aiming for as low a rate as possible
	static TIMER keystate_timer;
	keystate_timer.begin();
	while (LocalClient::KeystateTaskThread::is_running() && LocalClient::is_connected()) {
		if (keystate_timer.get_ms() > KEYSTATE_GRANULARITY_MS) {
			update_keystate(keys);
			post_keystate();
			keystate_timer.begin();
			long wait_ms = KEYSTATE_GRANULARITY_MS - keystate_timer.get_ms();
			if (wait_ms > 1) { SLEEP_MS(wait_ms); }
		}
	}
}
开发者ID:elipp,项目名称:wl_gl,代码行数:15,代码来源:client.cpp


示例4: stopwatch_event

 stopwatch_event(uint32_t waitms,
                 std::function<void(void)>&& d,
                 const TIMER& in_ms_timer) :
     ms_timer([&in_ms_timer]() { return in_ms_timer.milliseconds(); }),
     _canceled(IS_NOT_CANCELED),
     _step(IS_NOT_STARTED),
     waitms(waitms),
     d(std::move(d)),
     lastms(ms_timer())
 { }
开发者ID:surmountian,项目名称:osi,代码行数:10,代码来源:stopwatch.hpp


示例5: mpi_reduce_timers

	/**
	 * Reduce all server timers to server master.
	 * @param timer
	 */
	void mpi_reduce_timers(TIMER& timer){
		sip::SIPMPIAttr &attr = sip::SIPMPIAttr::get_instance();
		sip::check(attr.is_server(), "Trying to reduce timer on a non-server rank !");
		long long * timers = timer.get_timers();
		long long * timer_counts = timer.get_timer_count();

		// Data to send to reduce
		long long * sendbuf = new long long[2*timer.max_slots + 1];
		sendbuf[0] = timer.max_slots;
		// The data will be structured as
		// Length of arrays 1 & 2
		// Array1 -> timer_switched_ array
		// Array2 -> timer_list_ array
		std::copy(timer_counts + 0, timer_counts + timer.max_slots, sendbuf+1);
		std::copy(timers + 0, timers + timer.max_slots, sendbuf+1+ timer.max_slots);

		long long * recvbuf = new long long[2*timer.max_slots + 1]();

		int server_master = attr.COMPANY_MASTER_RANK;
		MPI_Comm server_company = attr.company_communicator();

		MPI_Datatype server_timer_reduce_dt; // MPI Type for timer data to be reduced.
		MPI_Op server_timer_reduce_op;	// MPI OP to reduce timer data.
		SIPMPIUtils::check_err(MPI_Type_contiguous(timer.max_slots*2+1, MPI_LONG_LONG, &server_timer_reduce_dt));
		SIPMPIUtils::check_err(MPI_Type_commit(&server_timer_reduce_dt));
		SIPMPIUtils::check_err(MPI_Op_create((MPI_User_function *)server_timer_reduce_op_function, 1, &server_timer_reduce_op));

		SIPMPIUtils::check_err(MPI_Reduce(sendbuf, recvbuf, 1, server_timer_reduce_dt, server_timer_reduce_op, server_master, server_company));

		if (attr.is_company_master()){
			std::copy(recvbuf+1, recvbuf+1+timer.max_slots, timer_counts);
			std::copy(recvbuf+1+timer.max_slots, recvbuf+1+2*timer.max_slots, timers);
		}

		// Cleanup
		delete [] sendbuf;
		delete [] recvbuf;

		SIPMPIUtils::check_err(MPI_Type_free(&server_timer_reduce_dt));
		SIPMPIUtils::check_err(MPI_Op_free(&server_timer_reduce_op));
	}
开发者ID:BB-Goldstein,项目名称:aces4,代码行数:45,代码来源:server_timer.cpp


示例6: CheckTimers

void CheckTimers()
{
    //50 msecs were elasped
    std::list<TIMER*>::iterator itr;

    for(itr = gTimerList.begin(); itr != gTimerList.end();)
    {
        TIMER* curr = *itr;
        curr->current += 50;
        if ( curr->current >= curr->period )	{
            if (curr->routine(curr->period)) {
                curr->current -= curr->period;
            }
            else {
                delete curr;
                itr=gTimerList.erase(itr);
            }
        }
        else
            ++itr;
    }
}
开发者ID:Kreyl,项目名称:nute,代码行数:22,代码来源:OsEmulation.cpp


示例7: execute

	virtual void execute(TIMER& timer) {
		void ** tau_timers = timer.get_tau_timers();

		std::vector<std::string>::const_iterator it = line_to_str_.begin();
		for (int line_num = 0; it!= line_to_str_.end(); ++it, ++line_num){
			const std::string &line_str = *it;
			if (line_str != ""){

				int total_time_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::TOTALTIME);
				if (tau_timers[total_time_timer_offset] != NULL){
					// Set total time string
					std::stringstream tot_sstr;
					tot_sstr << sip::GlobalState::get_program_num() << ": " << line_num << ": "  << " Total " << line_str;
					const char *tau_string = tot_sstr.str().c_str();
					TAU_PROFILE_TIMER_SET_NAME(tau_timers[total_time_timer_offset], tau_string);
				}

				int block_wait_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::BLOCKWAITTIME);
				if (tau_timers[block_wait_timer_offset] != NULL){
					// Set block wait time string
					std::stringstream blkw_sstr;
					blkw_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " Blkwait " << line_str ;
					const char *tau_string = blkw_sstr.str().c_str();
					TAU_PROFILE_TIMER_SET_NAME(tau_timers[block_wait_timer_offset], tau_string);
				}

				int read_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::READTIME);
				if (tau_timers[read_timer_offset] != NULL){
					// Set disk read time string
					std::stringstream readd_sstr;
					readd_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " ReadDisk " << line_str ;
					const char *tau_string = readd_sstr.str().c_str();
					TAU_PROFILE_TIMER_SET_NAME(tau_timers[read_timer_offset], tau_string);
				}

				int write_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::WRITETIME);
				if (tau_timers[write_timer_offset] != NULL){
					// Set disk write time string
					std::stringstream writed_sstr;
					writed_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " WriteDisk " << line_str ;
					const char *tau_string = writed_sstr.str().c_str();
					TAU_PROFILE_TIMER_SET_NAME(tau_timers[write_timer_offset], tau_string);
				}

			}
		}
	}
开发者ID:BB-Goldstein,项目名称:aces4,代码行数:47,代码来源:server_timer.cpp


示例8: run_task

MDA_TASK_RETURN_CODE MDA_TASK_PATH:: run_task() {
    puts("Press q to quit");

    MDA_VISION_MODULE_PATH path_vision;
    MDA_VISION_MODULE_GATE gate_vision;
    MDA_TASK_RETURN_CODE ret_code = TASK_MISSING;
    
    TASK_STATE state = STARTING_GATE;
    bool done_gate = false;
    bool done_path = false;

    // read the starting orientation
    int starting_yaw = attitude_input->yaw();
    printf("Starting yaw: %d\n", starting_yaw);
    
    int GATE_DEPTH;
    read_mv_setting ("hacks.csv", "GATE_DEPTH", GATE_DEPTH);

    // gate depth
    if (HARDCODED_DEPTH > 350)
        set (DEPTH, 350);
    if (HARDCODED_DEPTH > 400)
        set (DEPTH, 400);
    set (DEPTH, GATE_DEPTH);
    //set(DEPTH, 100);

    // go to the starting orientation in case sinking changed it
    set (YAW, starting_yaw);

    //TIMER master_timer;
    TIMER timer;
    timer.restart();

    while (1) {

        IplImage* frame = NULL;
        MDA_VISION_RETURN_CODE vision_code = NO_TARGET;
        MDA_VISION_RETURN_CODE gate_vision_code = NO_TARGET;
        (void) gate_vision_code;
        /*if (!done_gate) {
            frame = image_input->get_image(FWD_IMG);
            if (!frame) {
                ret_code = TASK_ERROR;
                break;
            }
            gate_vision_code = gate_vision.filter(frame);
        }*/

        frame = image_input->get_image(DWN_IMG);
        if (!frame) {
            ret_code = TASK_ERROR;
            break;
        }
        vision_code = path_vision.filter(frame);
        
        // clear fwd image. RZ - do we need this?
        // This ensures the other camera is properly logged
        // and that the webcam cache is cleared so it stays in sync - VZ
        //image_input->ready_image(FWD_IMG);

        /**
        * Basic Algorithm:
        *  - Go to path
        *  - Align with path
        */

        if (!done_gate) {
            if (state == STARTING_GATE) {
                printf ("Starting Gate: Moving Foward at High Speed\n");
                set (SPEED, 5);

                if (timer.get_time() > MASTER_TIMEOUT) {
                    printf ("Starting Gate: Master Timer Timeout!!\n");
                    return TASK_MISSING;
                }
                /*else if (gate_vision_code == FULL_DETECT) {
                    printf ("Starting Gate: Full Detect\n");
                    int ang_x = gate_vision.get_angular_x();
                    set_yaw_change(ang_x);

                    if (gate_vision.get_range() < 420) { // finished the gate
                        printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
                        timer.restart();
                        while (timer.get_time() < 3) {
                            set(SPEED, 6);
                        }
                        set(SPEED, 0);
                        printf ("Gate Task Done!!\n");

                        // get ready for path task
                        done_gate = true;
                        set(YAW, starting_yaw);
                        state = STARTING_PATH;
                    }

                    timer.restart();
                }*/

                // if path vision saw something, go do the path task
                if (vision_code != NO_TARGET) {
//.........这里部分代码省略.........
开发者ID:JasonLiu0728,项目名称:MDA-Software,代码行数:101,代码来源:task_path.cpp


示例9: run_task

MDA_TASK_RETURN_CODE MDA_TASK_GATE:: run_task() {
    puts("Press q to quit");

    MDA_VISION_MODULE_GATE gate_vision;
    TASK_STATE state = STARTING;

    bool done_gate = false;
    MDA_TASK_RETURN_CODE ret_code = TASK_MISSING;

    // read the starting orientation
    int starting_yaw = attitude_input->yaw();
    printf("Starting yaw: %d\n", starting_yaw);
    
    MDA_TASK_BASE::starting_depth = attitude_input->depth();
    // gate depth
    set (DEPTH, HARDCODED_DEPTH-50/*MDA_TASK_BASE::starting_depth+GATE_DELTA_DEPTH*/);
    set (DEPTH, HARDCODED_DEPTH/*MDA_TASK_BASE::starting_depth+GATE_DELTA_DEPTH*/);

    // go to the starting orientation in case sinking changed it
    set (YAW, starting_yaw);

    static TIMER timer; // keeps track of time spent in each state
    static TIMER master_timer; // keeps track of time spent not having found the target
    static TIMER full_detect_timer; // keeps track of time since the last full detect
    timer.restart();
    master_timer.restart();
    full_detect_timer.restart();

    while (1) {
        IplImage* frame = image_input->get_image();
        if (!frame) {
            ret_code = TASK_ERROR;
            break;
        }
        MDA_VISION_RETURN_CODE vision_code = gate_vision.filter(frame);

        // clear dwn image. RZ - do we need this?
        // This ensures the other camera is properly logged
        // and that the webcam cache is cleared so it stays in sync - VZ
        image_input->ready_image(DWN_IMG);

        // static
        //static int prev_t = -1;

        /**
        * Basic Algorithm: (repeat)
        *  - Go straight foward in STARTING state until we see anything
        *  
        *    - If we saw a ONE_SEGMENT, calculate the course we should take to allow the segment to remain in view.
        *    - If we saw a FULL_DETECT, change course to face it
        *  - Always go forwards in increments and stop for 1 seconds to stare each time.
        */
        if (!done_gate) {
            if (state == STARTING) {
                printf ("Starting: Moving Foward at High Speed\n");
                set (SPEED, 9);

                if (master_timer.get_time() > MASTER_TIMEOUT) {
                    printf ("Master Timer Timeout!!\n");
                    return TASK_MISSING;
                }
                else if (vision_code == FULL_DETECT) {
                    printf ("FAST Foward: Full Detect\n");
                    //int ang_x = gate_vision.get_angular_x();
                    //set_yaw_change(ang_x);

                    if (gate_vision.get_range() < 420) {
                        done_gate = true;
                        printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
                    }

                    timer.restart();
                    full_detect_timer.restart();
                    master_timer.restart();
                }
                /*if (gate_vision.latest_frame_is_valid()) {
                    set (SPEED, 0);
                    master_timer.restart();
                    timer.restart();
                    gate_vision.clear_frames();
                    state = SLOW_FOWARD;
                }*/
            }
            else if (state == SLOW_FOWARD) {
                printf ("Slow Foward: Moving foward a little\n");
                set (SPEED, 4);

                if (timer.get_time() > 3) {
                    timer.restart();
                    gate_vision.clear_frames();
                    state = PANNING;
                }
                else if (vision_code == FULL_DETECT) {
                    printf ("Slow Foward: Full Detect\n");
                    int ang_x = gate_vision.get_angular_x();
                    set_yaw_change(ang_x);

                    if (gate_vision.get_range() < 420) {
                        done_gate = true;
                        printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
//.........这里部分代码省略.........
开发者ID:freshnewegg,项目名称:AquaTux,代码行数:101,代码来源:task_gate.cpp


示例10: PeekMessageEx


//.........这里部分代码省略.........
            }
            UNLOCK_MSGQ (pMsgQueue);
            return TRUE;
        }
#endif

        pMsg->message = MSG_PAINT;
        pMsg->wParam = 0;
        pMsg->lParam = 0;
        SET_PADD (NULL);

#ifdef _LITE_VERSION
        pHostingRoot = __mg_dsk_win;
#else
        pHostingRoot = pMsgQueue->pRootMainWin;
#endif

        if ( (hNeedPaint = msgCheckHostedTree (pHostingRoot)) ) {
            pMsg->hwnd = hNeedPaint;
            pWin = (PMAINWIN) hNeedPaint;
            pMsg->lParam = (LPARAM)(&pWin->InvRgn.rgn);
            UNLOCK_MSGQ (pMsgQueue);
            return TRUE;
        }
 
        /* no paint message */
        pMsgQueue->dwState &= ~QS_PAINT;
    }

    /*
     * handle timer here
     */
#ifdef _LITE_VERSION
    if (pMsgQueue->dwState & QS_DESKTIMER) {
        pMsg->hwnd = HWND_DESKTOP;
        pMsg->message = MSG_TIMER;
        pMsg->wParam = 0;
        pMsg->lParam = 0;

        if (uRemoveMsg == PM_REMOVE) {
            pMsgQueue->dwState &= ~QS_DESKTIMER;
        }
        return TRUE;
    }
#endif

    if (pMsgQueue->TimerMask && IS_MSG_WANTED(MSG_TIMER)) {
        int slot;
        TIMER* timer;

#ifndef _LITE_VERSION
        if (hWnd == HWND_DESKTOP) {
            pMsg->hwnd = hWnd;
            pMsg->message = MSG_TIMER;
            pMsg->wParam = 0;
            pMsg->lParam = 0;
            SET_PADD (NULL);

            if (uRemoveMsg == PM_REMOVE) {
                pMsgQueue->TimerMask = 0;
            }
            UNLOCK_MSGQ (pMsgQueue);
            return TRUE;
        }
#endif
开发者ID:VVillwin,项目名称:minigui,代码行数:66,代码来源:message.c


示例11: UpdateFrame

//Perform per-frame updates
void UpdateFrame()
{
	//set currentTime and timePassed
	static double lastTime=timer.GetTime();
	double currentTime=timer.GetTime();
	double timePassed=currentTime-lastTime;
	lastTime=currentTime;

	//Update window
	WINDOW::Instance()->Update();

	//Update the lights
	for(int i=0; i<numLights; ++i)
	{
		lights[i].position+=lights[i].velocity*float(timePassed)/1000;

		//bounce off the borders
		if(lights[i].position.x>1.0f && lights[i].velocity.x>0.0f)
			lights[i].velocity.x=-lights[i].velocity.x;
		if(lights[i].position.x<-1.0f && lights[i].velocity.x<0.0f)
			lights[i].velocity.x=-lights[i].velocity.x;

		if(lights[i].position.z>1.0f && lights[i].velocity.z>0.0f)
			lights[i].velocity.z=-lights[i].velocity.z;
		if(lights[i].position.z<-1.0f && lights[i].velocity.z<0.0f)
			lights[i].velocity.z=-lights[i].velocity.z;
	}
	
	//Toggle vertex program/fixed function
	if(WINDOW::Instance()->IsKeyPressed('1') && GLEE_NV_vertex_program)
	{
		useVP1=true;
		useVP2=false;
		useFixedFunction=false;
	}
	
	if(WINDOW::Instance()->IsKeyPressed('2') && GLEE_NV_vertex_program2)
	{
		useVP1=false;
		useVP2=true;
		useFixedFunction=false;
	}

	if(WINDOW::Instance()->IsKeyPressed('3'))
	{
		useVP1=false;
		useVP2=false;
		useFixedFunction=true;
	}

	//Render frame
	RenderFrame(currentTime, timePassed);
}
开发者ID:,项目名称:,代码行数:54,代码来源:


示例12: Keyboard

//Called when a key is pressed
void Keyboard(unsigned char key, int x, int y)
{
	//If escape is pressed, exit
	if(key==27)
		exit(0);

	//Use P to pause the animation and U to unpause
	if(key=='P' || key=='p')
		timer.Pause();

	if(key=='U' || key=='u')
		timer.Unpause();
}
开发者ID:shanfl,项目名称:collectcode,代码行数:14,代码来源:main.cpp


示例13: DemoInit

//Set up variables
bool DemoInit()
{
	if(!window.Init("Metaballs", 512, 512, 32, 24, 8, WINDOWED_SCREEN))
		return 0;											//quit if not created
	
	//set up grid
	if(!cubeGrid.CreateMemory())
		return false;
	if(!cubeGrid.Init(gridSize))
		return false;

	//set up metaballs
	for(int i=0; i<numMetaballs; i++)
		metaballs[i].Init(VECTOR3D(0.0f, 0.0f, 0.0f), 5.0f+float(i));

	//Set Up Colors
	diffuseColors[0].Set(0.345f, 0.843f, 0.902f, 1.0f);
	diffuseColors[1].Set(0.047f, 0.839f, 0.271f, 1.0f);
	diffuseColors[2].Set(0.976f, 0.213f, 0.847f, 1.0f);	

	//reset timer for start
	timer.Reset();
	
	return true;
}
开发者ID:,项目名称:,代码行数:26,代码来源:


示例14: StateGraphicsNext

void StateGraphicsNext(int state)
{
	if (StateGraphics == state)
	{
		return;
	}

	StateGraphicsTimer.Reset();
	StateGraphicsLast = StateGraphics;
	StateGraphics = state;

	// The visual target first appears in this state, so set graphics sync timer.
	if (StateGraphics == STATE_GO)
	{
		// Set graphics sync timer relative to offset of next vertical retrace.
		GraphicsTargetTimer.Reset(-GRAPHICS_VerticalRetraceOffsetTimeUntilNext());
	}
}
开发者ID:anosnowhong,项目名称:phantom,代码行数:18,代码来源:DynamicLearning_migrating.cpp


示例15: GraphicsScene

void GraphicsScene(void) // this is created by shyeo, isolating the gl routines only from GraphicsDisplay
{
	int attr;
	static matrix posn;

	// Display text.
	strncpy(GraphicsString, StateText[StateGraphics], STRLEN);
	GraphicsDisplayText();
	
	// Display rotating teapot during rest period.
	if (StateGraphics == STATE_REST)
	{
		glPushMatrix();
		GRAPHICS_ColorSet(GREEN);
		glRotated(ExperimentTimer.ElapsedSeconds() * 10.0 * PI, 1.0, 1.0, 1.0);
		glutWireTeapot(10.0);
		glPopMatrix();
		return;
	}
	
	// Display home position at start of trial.
	if ((StateGraphics >= STATE_SETUP) && (StateGraphics <= STATE_MOVING))
	{
		attr = RobotHome() ? HomeColor : NotHomeColor;
		//GRAPHICS_Circle(&StartPosition, HomeRadius, attr);
		GRAPHICS_Sphere(&StartPosition, HomeRadius, attr);
	}
	
	// Display target spheres when trial running.
	if ((StateGraphics >= STATE_GO) && (StateGraphics <= STATE_FINISH))
	{
		// Display target for movement.
		GRAPHICS_Sphere(&TargetPosition, TargetRadius, TargetColor);

		// Display graphics sync target for phototransistor.
		if (!GraphicsSyncPosition.iszero())
		{
			GRAPHICS_Sphere(&GraphicsSyncPosition, GraphicsSyncRadius, GraphicsSyncColor);
		}
	}

	// Display finish position.
	if ((StateGraphics > STATE_MOVING) && (StateGraphics <= STATE_INTERTRIAL))
	{
		attr = RobotHome() ? HomeColor : NotHomeColor;
		GRAPHICS_Sphere(&FinishPosition, HomeRadius, attr);
	}

	// Display robot position cursor.
	if ((StateGraphics != STATE_ERROR) && (VisualFeedback || RobotHome()))
	{
		posn = CursorPosition;
		posn(3, 1) += 2.0*HomeRadius;
		GRAPHICS_Sphere(&posn, CursorRadius, CursorColor);
	}
}
开发者ID:anosnowhong,项目名称:phantom,代码行数:56,代码来源:DynamicLearning_migrating.cpp


示例16: StateNext

void StateNext(int state)
{
	if (State == state)
	{
		return;
	}

	printf("STATE: %s[%d] > %s[%d] (%.0lf msec).\n", StateText[State], State, StateText[state], state, StateTimer.Elapsed());
	StateTimer.Reset();
	StateLast = State;
	State = state;
}
开发者ID:anosnowhong,项目名称:phantom,代码行数:12,代码来源:DynamicLearning_migrating.cpp


示例17: RenderFrame

//draw a frame
void RenderFrame()
{
	//Clear buffers
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();										//reset modelview matrix


	glEnable(GL_LIGHTING);
	glTranslatef(0.0f, 0.0f, -30.0f);
	glRotatef((float)timer.GetTime()/30, 1.0f, 0.0f, 1.0f);
	cubeGrid.DrawSurface(threshold);
	glDisable(GL_LIGHTING);

	
	fpsCounter.Update();											//update frames per second counter
	glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
	window.StartTextMode();
	window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps());			//print the fps
	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	window.Print(0, 48, "Grid Size: %d", gridSize);
	window.Print(0, 68, "%d triangles drawn", cubeGrid.numFacesDrawn);
	window.EndTextMode();
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	if(window.isKeyPressed(VK_F1))
	{
		window.SaveScreenshot();
		window.SetKeyReleased(VK_F1);
	}

	window.SwapBuffers();									//swap buffers

	//check for any opengl errors
	window.CheckGLError();

	//quit if necessary
	if(window.isKeyPressed(VK_ESCAPE))
		PostQuitMessage(0);
}
开发者ID:,项目名称:,代码行数:40,代码来源:


示例18: Display

//Called to draw scene
void Display(void)
{
	//angle of spheres in scene. Calculate from time
	float angle=timer.GetTime()/10;	



	//First pass - from light's point of view
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(lightProjectionMatrix);

	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(lightViewMatrix);

	//Use viewport the same size as the shadow map
	glViewport(0, 0, shadowMapSize, shadowMapSize);

	//Draw back faces into the shadow map
	glCullFace(GL_FRONT);

	//Disable color writes, and use flat shading for speed
	glShadeModel(GL_FLAT);
	glColorMask(0, 0, 0, 0);
	
	//Draw the scene
	DrawScene(angle);

	//Read the depth buffer into the shadow map texture
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);

	//restore states
	glCullFace(GL_BACK);
	glShadeModel(GL_SMOOTH);
	glColorMask(1, 1, 1, 1);
	

	

	//2nd pass - Draw from camera's point of view
	glClear(GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadMatrixf(cameraProjectionMatrix);
	
	glMatrixMode(GL_MODELVIEW);
	glLoadMatrixf(cameraViewMatrix);

	glViewport(0, 0, windowWidth, windowHeight);

	//Use dim light to represent shadowed areas
	glLightfv(GL_LIGHT1, GL_POSITION, VECTOR4D(lightPosition));
	glLightfv(GL_LIGHT1, GL_AMBIENT, white*0.2f);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, white*0.2f);
	glLightfv(GL_LIGHT1, GL_SPECULAR, black);
	glEnable(GL_LIGHT1);
	glEnable(GL_LIGHTING);

	DrawScene(angle);
	


	//3rd pass
	//Draw with bright light
	glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
	glLightfv(GL_LIGHT1, GL_SPECULAR, white);

	//Calculate texture matrix for projection
	//This matrix takes us from eye space to the light's clip space
	//It is postmultiplied by the inverse of the current view matrix when specifying texgen
	static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
								0.0f, 0.5f, 0.0f, 0.0f,
								0.0f, 0.0f, 0.5f, 0.0f,
								0.5f, 0.5f, 0.5f, 1.0f);	//bias from [-1, 1] to [0, 1]
	MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix;
	//MATRIX4X4 textureMatrix=lightProjectionMatrix*lightViewMatrix;
	//Set up texture coordinate generation.
	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
	glEnable(GL_TEXTURE_GEN_S);

	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
	glEnable(GL_TEXTURE_GEN_T);

	glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));
	glEnable(GL_TEXTURE_GEN_R);

	glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
	glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));
	glEnable(GL_TEXTURE_GEN_Q);

	//Bind & enable shadow map texture
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glEnable(GL_TEXTURE_2D);

//.........这里部分代码省略.........
开发者ID:shanfl,项目名称:collectcode,代码行数:101,代码来源:main.cpp


示例19: Init

//Called for initiation
bool Init(void)
{
	//Check for necessary extensions
	if(!GLEE_ARB_depth_texture || !GLEE_ARB_shadow)
	{
		printf("I require ARB_depth_texture and ARB_shadow extensionsn\n");
		return false;
	}
	
	//Load identity modelview
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	//Shading states
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

	//Depth states
	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);

	glEnable(GL_CULL_FACE);

	//We use glScale when drawing the scene
	glEnable(GL_NORMALIZE);

	//Create the shadow map texture
	glGenTextures(1, &shadowMapTexture);
	glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
	glTexImage2D(	GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0,
					GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

	//Use the color as the ambient and diffuse material
	glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);
	
	//White specular material color, shininess 16
	glMaterialfv(GL_FRONT, GL_SPECULAR, white);
	glMaterialf(GL_FRONT, GL_SHININESS, 16.0f);

	//Calculate & save matrices
	glPushMatrix();
	
	glLoadIdentity();
	gluPerspective(45.0f, (float)windowWidth/windowHeight, 1.0f, 100.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraProjectionMatrix);
	
	glLoadIdentity();
	gluLookAt(cameraPosition.x, cameraPosition.y, cameraPosition.z,
				0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, cameraViewMatrix);
	
	glLoadIdentity();
	gluPerspective(45.0f, 1.0f, 2.0f, 8.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightProjectionMatrix);
	
	glLoadIdentity();
	gluLookAt(	lightPosition.x, lightPosition.y, lightPosition.z,
				0.0f, 0.0f, 0.0f,
				0.0f, 1.0f, 0.0f);
	glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix);
	
	glPopMatrix();

	//Reset timer
	timer.Reset();

	return true;
}
开发者ID:shanfl,项目名称:collectcode,代码行数:78,代码来源:main.cpp



注:本文中的TIMER类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TIStream类代码示例发布时间:2022-05-31
下一篇:
C++ TILx类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap