You Are Here:

Community: Wiki

This page was last modified 08:23, 30 March 2009.

How to draw image to screen directly

From Forum Nokia Wiki



The speed of image drawing is very important in game development, but the Symbian OS window frame does not offer full support for games. We need to access the screen buffer directly to provide fluent animation.

Library Needed:

LIBRARY  ws32.lib //RWsSession, CWsScreenDevice, RWindowGroup, CDirectScreenAccess
LIBRARY  bitgdi.lib  //CFbsBitGc


Display.h

#include <w32std.h> //RWsSession, CWsScreenDevice, RWindowGroup, CDirectScreenAccess
#include <bitstd.h>  //CFbsBitGc
 
 
class CDisplay : public MDirectScreenAccess
{
public:
	static CDisplay*NewL( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
	static CDisplay*NewLC( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
	~CDisplay();
 
	inline CWsScreenDevice& GetScreenDevice()
	{
		return m_pScreenDevice;
	}
 
	inline RWindow& GetWindow()
	{
		return m_pWindow;
	}
 
	inline CFbsBitGc* GetScreenGc()
	{
		return m_pGc;
	}
 
	void Start();
	void Stop();
	void Update();
 
private:
	CDisplay( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow );
	void ConstructL();
	void Restart( RDirectScreenAccess::TTerminationReasons aReason );
	void AbortNow( RDirectScreenAccess::TTerminationReasons aReason );
 
private:
	CWsScreenDevice&	m_pScreenDevice;
	RWsSession&		m_pClient;
	RWindow&		m_pWindow;
 
	CDirectScreenAccess*	m_pDirectScreenAccess;
	RRegion*		m_pRegion;
	CFbsBitGc*		m_pGc;
 
	TBool			m_bDrawing;
};


Display.cpp

#include "Display.h"
 
 
CDisplay* CDisplay::NewL( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow )
{
	CDisplay* self = NewLC( pClient, pScreenDevice, pWindow );
	CleanupStack::Pop( self );
	return self;
}
 
CDisplay* CDisplay::NewLC( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow )
{
	CDisplay* self = new ( ELeave ) CDisplay( pClient, pScreenDevice, pWindow );
	CleanupStack::PushL( self );
	self->ConstructL();
	return self;
}
 
CDisplay::CDisplay( RWsSession& pClient, CWsScreenDevice& pScreenDevice, RWindow& pWindow ) :
m_pClient( pClient ),
m_pScreenDevice( pScreenDevice ),
m_pWindow( pWindow )
{
	m_pDirectScreenAccess = NULL;
	m_pRegion = NULL;
	m_pGc = NULL;
 
	m_bDrawing = EFalse;
}
 
CDisplay::~CDisplay()
{
	delete m_pDirectScreenAccess;
}
 
void CDisplay::ConstructL()
{
	m_pDirectScreenAccess = CDirectScreenAccess::NewL( m_pClient, m_pScreenDevice, m_pWindow, *this );
}
 
void CDisplay::Start()
{
	if( !m_bDrawing )
	{
		TRAPD( dsaErr, m_pDirectScreenAccess->StartL() );
		if( dsaErr == KErrNone )
		{
			m_pGc = m_pDirectScreenAccess->Gc();
			m_pRegion = m_pDirectScreenAccess->DrawingRegion();
			m_pGc->SetClippingRegion( m_pRegion );
			m_bDrawing = ETrue;
		}
	}
}
 
void CDisplay::Stop()
{
	if( m_bDrawing )
	{
		m_bDrawing = EFalse;
	}
}
 
void CDisplay::Update()
{
	m_pDirectScreenAccess->ScreenDevice()->Update();
}
 
void CDisplay::Restart( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
{
	Start();
}
 
void CDisplay::AbortNow( RDirectScreenAccess::TTerminationReasons /*aReason*/ )
{
	m_pDirectScreenAccess->Cancel();
	m_bDrawing = EFalse;
}

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditFurlTechnocratiMagnoliaTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fHowE5ftoE5fdrawE5fimageE5ftoE5fscreenE5fdirectlyX qdcZpublisherQUxhttpE3aE2fE2fswE2enokiaE2ecomE2fidE2fc764fd1cE2d8b06E2d499aE2d9a6aE2d17c3903d5a65E2fforumE5fnokiaE5fcrawlerE5fagentX qdcZtitleQSxHowE20toE20drawE20imageE20toE20screenE20directlyE20E2dE20ForumE20NokiaE20WikiX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfnTypeZCommunityContentQ qdcZtypeQUqfnTypeZE52esourceQ qdcZtypeQUqfnTypeZWebpageQ qdcZtypeQUqfnTypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qrssZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qfnZdistributionQUxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2fX qfnZtopicQUqfnTopicZentertainmentQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZgamesQRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtopicQUqfnTopicZseriesE5f60QRqdcZtypeQUqrdfsZE52esourceQRqmarsZrelevanceQNx100X qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZE52esourceQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qfnZupdatedQDx2008E2d10E2d02X qfnZuserE5ftagQSxcakngridX qfnZuserE5ftagQSxentertainmentX qfnZuserE5ftagQSxgamesX qfnZuserE5ftagQSxs60X qmarsZdescriptionQSxEa0E20WikiE20javaE20symbianE5fosE20s60E20maemoE20cE2bE2bE20WikiE20HomeE20WikiE20HelpE20OverviewE20GlossaryE20CreateE20PageE20ProposeE20anE20ArticleE20SpotlightE20TopicE20E2dE20WE52TE20WidgetsE20ProgrammingE20E4canguageE20E2dE20SymbianE20CE2bE2bE20E2dE20OpenE20CE2fCE2bE2bE20E2dE20JavaE20E2dE20FlashE20E4citeE20E2dE20PythonE20WebE20TechnologiesE20E2dE20WE52TE20WidgetsE20E2dE20WidSetsE20ToolsE20andE20SE44KE20CodeE20E45E78amplesE20KnowledgeE20BaseE20TechnologyE20AreasE20SoftwareE20PlatformsE20E44evelopmentE20ProcessE20E3fE3fWikiE20ChineseE20E3fE3fE3fWikiE20JapaneseE20PortugueseE2fBrazilianE20E52ussianE20WhatE20linksE20hereE20UploadE20fileE20SpecialE20pagesE20PrintableE20versionE44ownloadE20asE20PE44FE20GoE20ToE20E2eE2eE2eX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfnTypeZCommunityContentQ qrdfZtypeQUqfnTypeZE52esourceQ qrdfZtypeQUqfnTypeZWebpageQ qrdfZtypeQUqfnTypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ
User Rating: qfnZuserE5FratingQNx3E2E0000X