Beispiel #1
0
void RenderControl::OnPaint(wxPaintEvent& WXUNUSED(event))
{   
#if 0
	// TODO: Seems wxWidgets won't invalidate the entire window region
	// on things like window overlap or tooltip hovering, so we need 
	// to force a complete redraw.
	Refresh();
#endif

	// From the PaintEvent docs: "the application must always create
	// a wxPaintDC object, even if you do not use it."
	// http://docs.wxwidgets.org/trunk/classwx_paint_event.html
	wxPaintDC dc(this);

	if( frameRenderTimer.IsRunning() )
	{
		onRender();
	
		// Swaps the front and back buffers.
		window->update();
	}
}
Beispiel #2
0
int main(void)
{
	jfWindowManager* wm = new jfSDLWindowManager();
	jfObjLoader* objLoader = new jfObjLoader();
	wm->init();
	jfWindow* window = wm->createWindow("test");

	initGL(*window);

	jfModel model;
	objLoader->loadFromFile("../../media/models/teapot_3.obj", &model);
	
	jfModelDrawer drawer;
	drawer.draw(model);
	for(int i = 0 ; i < 10000 ; i++)
	{
		onRender(drawer,model);
	}
	delete wm;
	delete objLoader;
	return 0;		
}
Beispiel #3
0
int BallGame::OnExecute() {
	if(onInit() == false) {
	        return -1;
	    }

	    SDL_Event Event;

	    while(running) {
	        while(SDL_PollEvent(&Event)) {
	            onEvent(&Event);
	        }

	        onLoop();
	        if (onRender() == false) {
	        	return -1;
	        }
	    }

	    onCleanup();

	    return 0;
}
        //-----------------------------------------------------------------------------------------------------------
        bool AndroidApplication::run()
        {
                float elapsedTime = 0.0f;
                timer_.reset();

                while(shouldRun_)
                {
                        int ident;
                        int events;
                        android_poll_source* source;

                        while((ident = ALooper_pollAll(isPaused_ ? -1 : 0, nullptr, &events,
                                                       reinterpret_cast<void**>(&source))) >= 0)
                        {
                                if(source != nullptr)
                                        source->process(state_, source);

                                if(state_->destroyRequested != 0)
                                {
                                        onDestroy();
                                        return true;
                                }
                        }

                        if(!isPaused_ && isInitialized_)
                        {
                                timer_.reset();

                                onUpdate(elapsedTime);
                                onRender(elapsedTime);

                                elapsedTime = timer_.getElapsedTime();
                                setPressedControlButtonsMask(0);
                        }
                }

                return true;
        }
Beispiel #5
0
int App::onExecute()
{
    if (onInit() == false)
    {
        return -1;
    }

    SDL_Event event;

    timespec start, end;
    double elapsed;
    long waitusec;
    while (m_running)
    {
        clock_gettime(CLOCK_MONOTONIC, &start);
        while(SDL_PollEvent(&event))
        {
            onEvent(&event);
        }

        onLoop();
        onRender();
        
        clock_gettime(CLOCK_MONOTONIC, &end);
        elapsed = double(end.tv_sec - start.tv_sec) + (end.tv_nsec - start.tv_nsec)/double(1000000000);
        
        if (elapsed < double(1/m_targetFps))
        {
            waitusec = (double(1/m_targetFps) - elapsed) * 1000000;
            usleep(waitusec);
        }
    }

    onCleanup();

    return 0;
}
Beispiel #6
0
int JoltApp::doExecute() {
    
    if(!doInit()) {
        return -1;
    }
    
    SDL_Event evt;
    
    JoltConsole::logInfo("App","Starting game loop.");
    while(running) {
        while(SDL_PollEvent(&evt)) {
            onEvent(&evt);
        }
        
        onLoop();
        onRender();
        //JoltConsole::logInfo("Main","Loop called at %i", SDL_GetTicks());
    }
    
    doCleanup();
    
    return 0;
    
}
Beispiel #7
0
void Game::startGame()
{
  lastTime = getAbsolutTime();

  // Start game loop
  while (app->isOpen())
  {
    // Process events
    sf::Event event;

    while (app->pollEvent(event))
    {
      // Close window : exit
      if (event.type == sf::Event::Closed)
        app->close();

    }

    onUpdate();
    onRender();
  }

  quitGame();
}
Beispiel #8
0
bool CapApp::onInit(int argc, char* argv[])
{
	(void)argc;
	(void)argv;

	// ----------------------------------------------
	// FTP	
	cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
	cellNetCtlInit();
	cellSysmoduleLoadModule(CELL_SYSMODULE_HTTP);
	sys_net_initialize_network();
	ftp_on();

	// Load settings...
	if(!iniRead()) {
		iniWrite(); // create settings file...
	}

	cellSysmoduleLoadModule(CELL_SYSMODULE_FS);

	cellSysmoduleLoadModule(CELL_SYSMODULE_SYSUTIL_SCREENSHOT);
	cellScreenShotEnable();

	InputInit();

	while(!videoOutIsReady())
	{
		// ...
	}


	PSGLinitOptions options = 
	{
		enable:					PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS,
		maxSPUs:				1,
		initializeSPUs:			GL_FALSE,
		persistentMemorySize:	0,
		transientMemorySize:	0,
		errorConsole:			0,
		fifoSize:				0,  
		hostMemorySize:			128* 1024*1024,  // 128 mbs for host memory 
	};

#if CELL_SDK_VERSION < 0x340000
	options.enable |=	PSGL_INIT_HOST_MEMORY_SIZE;
#endif

	// Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL
	sys_spu_initialize(6, 1);
	psglInit(&options);

	const unsigned int resolutions[] = { 
		CELL_VIDEO_OUT_RESOLUTION_1080, 
		CELL_VIDEO_OUT_RESOLUTION_960x1080, 
		CELL_VIDEO_OUT_RESOLUTION_720, 
		CELL_VIDEO_OUT_RESOLUTION_480 
	};

	const int numResolutions = sizeof(resolutions) / sizeof(resolutions[0]);

	int bestResolution = chooseBestResolution(resolutions,numResolutions);

	getResolutionWidthHeight(bestResolution, deviceWidth, deviceHeight);

	if(bestResolution)
	{
		PSGLdeviceParameters params;

		params.enable				= PSGL_DEVICE_PARAMETERS_COLOR_FORMAT |
									  PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT |
									  PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE;
		params.colorFormat			= GL_ARGB_SCE;
		params.depthFormat			= GL_NONE;
		params.multisamplingMode	= GL_MULTISAMPLING_NONE_SCE;
		params.enable				|= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT;
		params.width				= deviceWidth;
		params.height				= deviceHeight;

		device						= psglCreateDeviceExtended(&params);
		context						= psglCreateContext();

		psglMakeCurrent(context, device);
		psglResetCurrentContext();

		initGraphics();

		if( cellSysutilRegisterCallback( 0, callback_sysutil_exit, NULL ) < 0 ) {
			//...
		}

		dbgFontInit();

		fbaRL = new c_fbaRL();

		while(bRun)
		{
			onRender();
			onUpdate();
			cellSysutilCheckCallback();
		}

	} else {
		// resolution error...
	}

	ftp_off();

	onShutdown();

	return false;
}

void CapApp::onRender()
{
	if(fbaRL) { fbaRL->DlgDisplayFrame(); }

	// get render target buffer dimensions and set viewport	
	psglGetRenderBufferDimensions(device,&app.renderWidth,&app.renderHeight);

	glViewport(0, 0, app.renderWidth, app.renderHeight);

	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if(fbaRL) { fbaRL->RenderBackground(); }
	if(fbaRL) { fbaRL->nFrameStep = 0; fbaRL->DisplayFrame(); }
	if(fbaRL) { fbaRL->nFrameStep = 1; fbaRL->DisplayFrame(); }
	dbgFontDraw();

	psglSwap();
}

bool CapApp::onUpdate()
{
	if(!mFrame) mFrame = 0;
	mFrame++;

	InputFrameStart();
	if(fbaRL) fbaRL->InputFrame();
	InputFrameEnd();	

	return true;
}

void CapApp::onShutdown()
{
	iniWrite(); // save settings

	if(context) psglDestroyContext(context);
	if(device) psglDestroyDevice(device);

	InputExit();
	psglExit();
}
void RenderObject::renderCall()
{

	//RenderObjectLayer *rlayer = core->getRenderObjectLayer(getTopLayer());

	if (positionSnapTo)
		this->position = *positionSnapTo;

	position += offset;

#ifdef BBGE_BUILD_DIRECTX
	if (!RENDEROBJECT_FASTTRANSFORM)
		core->getD3DMatrixStack()->Push();
#endif

#ifdef BBGE_BUILD_OPENGL
	if (!RENDEROBJECT_FASTTRANSFORM)
		glPushMatrix();
	if (!RENDEROBJECT_SHAREATTRIBUTES)
	{
		glPushAttrib(GL_ALL_ATTRIB_BITS);
	}
#endif


	if (!RENDEROBJECT_FASTTRANSFORM)
	{
		if (layer != LR_NONE)
		{
			RenderObjectLayer *l = &core->renderObjectLayers[layer];
			if (l->followCamera != NO_FOLLOW_CAMERA)
			{
				followCamera = l->followCamera;
			}
		}
		if (followCamera!=0 && !parent)
		{
			if (followCamera == 1)
			{
#ifdef BBGE_BUILD_OPENGL
			 	glLoadIdentity();
				glScalef(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
				glTranslatef(position.x, position.y, position.z);
				if (isfh())
				{
					glDisable(GL_CULL_FACE);
					glRotatef(180, 0, 1, 0);
				}

				if (core->mode == Core::MODE_3D)
				{
					glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
					glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
				}

				glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
#endif
#ifdef BBGE_BUILD_DIRECTX
				core->getD3DMatrixStack()->LoadIdentity();
				core->scaleMatrixStack(core->globalResolutionScale.x, core->globalResolutionScale.y,0);
				core->translateMatrixStack(position.x, position.y, 0);
				if (isfh())
				{
					//HACK: disable cull ->
					core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180));
				}
				core->rotateMatrixStack(rotation.z + rotationOffset.z);
#endif
			}
			else
			{
				Vector pos = getFollowCameraPosition();

#ifdef BBGE_BUILD_OPENGL
				glTranslatef(pos.x, pos.y, pos.z);
				if (isfh())
				{
					glDisable(GL_CULL_FACE);
					glRotatef(180, 0, 1, 0);
				}
				if (core->mode == Core::MODE_3D)
				{
					glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
					glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
				}
				glRotatef(rotation.z+rotationOffset.z, 0, 0, 1);
#endif
#ifdef BBGE_BUILD_DIRECTX
				core->translateMatrixStack(pos.x, pos.y, 0);
				if (isfh())
				{
					//HACK: disable cull ->
					core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180));
				}
				core->rotateMatrixStack(rotation.z + rotationOffset.z);
#endif
			}
		}
		else
		{

#ifdef BBGE_BUILD_OPENGL
			glTranslatef(position.x, position.y, position.z);
#endif
#ifdef BBGE_BUILD_DIRECTX
			core->translateMatrixStack(position.x, position.y, 0);
#endif

#ifdef BBGE_BUILD_OPENGL
			if (RenderObject::renderPaths && position.data && position.data->path.getNumPathNodes() > 0)
			{
				glLineWidth(4);
				glEnable(GL_BLEND);
				
				int i = 0;
				glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
				glBindTexture(GL_TEXTURE_2D, 0);

				glBegin(GL_LINES);
				for (i = 0; i < position.data->path.getNumPathNodes()-1; i++)
				{
					glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y);
					glVertex2f(position.data->path.getPathNode(i+1)->value.x-position.x, position.data->path.getPathNode(i+1)->value.y-position.y);
				}
				glEnd();

				glPointSize(20);
				glBegin(GL_POINTS);
				glColor4f(0.5,0.5,1,1);
				for (i = 0; i < position.data->path.getNumPathNodes(); i++)
				{
					glVertex2f(position.data->path.getPathNode(i)->value.x-position.x, position.data->path.getPathNode(i)->value.y-position.y);
				}
				glEnd();
			}
#endif
#ifdef BBGE_BUILD_OPENGL

			if (core->mode == Core::MODE_3D)
			{
				glRotatef(rotation.x+rotationOffset.x, 1, 0, 0);
				glRotatef(rotation.y+rotationOffset.y, 0, 1, 0);
			}

			glRotatef(rotation.z+rotationOffset.z, 0, 0, 1); 
			if (isfh())
			{
				glDisable(GL_CULL_FACE);
				glRotatef(180, 0, 1, 0);
			}
#endif
#ifdef BBGE_BUILD_DIRECTX
			//core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 0, 1), rotation.z+rotationOffset.z);
			core->rotateMatrixStack(rotation.z + rotationOffset.z);
			if (isfh())
			{
				//HACK: disable cull
				core->getD3DDevice()->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
				//core->getD3DMatrixStack()->Scale(-1, 1, 1);
				//core->applyMatrixStackToWorld();
				core->getD3DMatrixStack()->RotateAxisLocal(&D3DXVECTOR3(0, 1, 0), D3DXToRadian(180));
				//core->applyMatrixStackToWorld();
			}
#endif
		}
				
#ifdef BBGE_BUILD_OPENGL	
		glTranslatef(beforeScaleOffset.x, beforeScaleOffset.y, beforeScaleOffset.z);
		if (core->mode == Core::MODE_3D)
			glScalef(scale.x, scale.y, scale.z);
		else
			glScalef(scale.x, scale.y, 1);
		glTranslatef(internalOffset.x, internalOffset.y, internalOffset.z);
#endif
#ifdef BBGE_BUILD_DIRECTX
		core->translateMatrixStack(beforeScaleOffset.x, beforeScaleOffset.y, 0);
		core->scaleMatrixStack(scale.x, scale.y, 1);
		core->translateMatrixStack(internalOffset.x, internalOffset.y, 0);

		core->applyMatrixStackToWorld();
#endif


		//glDisable(GL_CULL_FACE);
		/* Never set anywhere.  --achurch
		if (renderOrigin)
		{
#ifdef BBGE_BUILD_OPENGL
			  glBegin(GL_TRIANGLES);
				glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
				glVertex3f(0.0f, 5.0f, 0.0f);
				glVertex3f(50.0f, 0.0f, 0.0f);
				glVertex3f(0.0f, -5.0f, 0.0f);

				glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
				glVertex3f(0.0f, 0.0f, 5.0f);
				glVertex3f(0.0f, 50.0f, 0.0f);
				glVertex3f(0.0f, 0.0f, -5.0f);

				glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
				glVertex3f(5.0f, 0.0f, 0.0f);
				glVertex3f(0.0f, 0.0f, 50.0f);
				glVertex3f(-5.0f, 0.0f, 0.0f);
			glEnd();
#endif
		}
		*/
	}

	for (Children::iterator i = children.begin(); i != children.end(); i++)
	{
		if (!(*i)->isDead() && (*i)->renderBeforeParent)
			(*i)->render();
	}


	//if (useColor)
	{
#ifdef BBGE_BUILD_OPENGL
		if (rlayer)
			glColor4f(color.x * rlayer->color.x, color.y * rlayer->color.y, color.z * rlayer->color.z, alpha.x*alphaMod);
		else
			glColor4f(color.x, color.y, color.z, alpha.x*alphaMod);
#elif defined(BBGE_BUILD_DIRECTX)
		core->setColor(color.x, color.y, color.z, alpha.x*alphaMod);
#endif
	}
	
	if (texture)
	{

#ifdef BBGE_BUILD_OPENGL
		if (texture->textures[0] != lastTextureApplied || repeatTexture != lastTextureRepeat)
		{
			texture->apply(repeatTexture);
			lastTextureRepeat = repeatTexture;
			lastTextureApplied = texture->textures[0];
		}
#endif
#ifdef BBGE_BUILD_DIRECTX
		texture->apply(repeatTexture);
#endif
	}
	else
	{
		if (lastTextureApplied != 0 || repeatTexture != lastTextureRepeat)
		{
#ifdef BBGE_BUILD_OPENGL
			glBindTexture(GL_TEXTURE_2D, 0);
#endif
#ifdef BBGE_BUILD_DIRECTX
			core->bindTexture(0, 0);
#endif
			lastTextureApplied = 0;
			lastTextureRepeat = repeatTexture;
		}
	}
	
	applyBlendType();


	bool doRender = true;
	int pass = renderPass;
	if (core->currentLayerPass != RENDER_ALL && renderPass != RENDER_ALL)
	{
		RenderObject *top = getTopParent();
		if (top)
		{
			if (top->overrideRenderPass != OVERRIDE_NONE)
				pass = top->overrideRenderPass;
		}

		doRender = (core->currentLayerPass == pass);
	}

	if (renderCollisionShape)
		renderCollision();

	if (doRender)
		onRender();

		//collisionShape.render();
	if (!RENDEROBJECT_SHAREATTRIBUTES)
	{
		glPopAttrib();
	}

	for (Children::iterator i = children.begin(); i != children.end(); i++)
	{
		if (!(*i)->isDead() && !(*i)->renderBeforeParent)
			(*i)->render();
	}


	if (!RENDEROBJECT_FASTTRANSFORM)
	{
#ifdef BBGE_BUILD_OPENGL
		glPopMatrix();
#endif
#ifdef BBGE_BUILD_DIRECTX
		core->getD3DMatrixStack()->Pop();
		core->applyMatrixStackToWorld();
#endif
	}


	position -= offset;

	if (integerizePositionForRender)
	{
		position = savePosition;
	}
}
Beispiel #10
0
void Modifier::preRender(void) {
	if(startTime != NULL) { // set this NULL to stop/bypass
		onRender(SDL_GetTicks() - startTime);
	}
};
Beispiel #11
0
int Saloon::start() {
	if(_window != nullptr) {

		// Create an OpenGL context associated with the window.
		SDL_GLContext glContext = SDL_GL_CreateContext(_window);

		// Init and check for GL Errors.
		glInit(_displayWidth, _displayHeight);

		GLenum error = glGetError();
		if( error != GL_NO_ERROR )
		{
			logSDLError(std::cout, "GL INIT");
			return 1;
		}

		LTimer fpsTimer;
		fpsTimer.start();
		Uint32 frames = 0, FPS = 0;

		//Our event structure
		SDL_Event e;
		bool quit = false;

		int curTime, prevTime = SDL_GetTicks();

		BMFont debugFont("Fonts/system16.fnt");

		onCreate();


		while (!quit){

			while (SDL_PollEvent(&e)){
				if (e.type == SDL_QUIT)
					quit = true;
				//Use number input to select which clip should be drawn
				if (e.type == SDL_KEYDOWN){
					switch (e.key.keysym.sym){
						case SDLK_ESCAPE:
							quit = true;
							break;
						case SDLK_TAB:
							if(_debugEnabled) {
								setVSyncEnabled(false);
							}
							break;
						default:
							break;
					}
				}
				else if(e.type == SDL_KEYUP) {
					switch (e.key.keysym.sym){
						case SDLK_TAB:
							if(_debugEnabled) {
								setVSyncEnabled(true);
							}
							break;
						default:
							break;
					}
				}
			}

			if(_debugEnabled) {
				debugStart();

				curTime = SDL_GetTicks();

				deltaTime = (curTime - prevTime) / 1000.0f;

				prevTime = curTime;

				if(fpsTimer.getTicks() >= 1000) {
					FPS = frames;
					frames = 0;
					fpsTimer.reset();
				}

				frames++;

				debugWatch("FPS", FPS);
			}

			onUpdate();

			glClear(GL_COLOR_BUFFER_BIT);

			//Reset modelview matrix
			glMatrixMode( GL_MODELVIEW );
			glLoadIdentity();

			glPushMatrix();

			glTranslatef(_halfDisplayWidth, _halfDisplayHeight, 0.0f);

			glPushMatrix();
			// Camera transformations
			glScalef(_camZoom, _camZoom, 1.0f);
			glRotatef(_camAng, 0, 0, 1);
			glTranslatef(-_camX, _camY, 0);

			onRender();

			glPopMatrix();

			glPopMatrix();

			glColor4(_debugColor);
			debugDraw(debugFont);

			SDL_GL_SwapWindow(_window);

		}

		onDestroy();

		glDestroy();

		// Once finished with OpenGL functions, the SDL_GLContext can be deleted.
		SDL_GL_DeleteContext(glContext);
		SDL_DestroyWindow(_window);

		TTF_Quit();
		IMG_Quit();
		SDL_Quit();
		return 0;
	}
	else {
		logSDLError(std::cout, "Saloon::start");
		return 1;
	}

}