Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Help with Render States

This topic is 5167 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well I''m really trying hard to keep my engine platform independant on both the operating system, and the graphics API side of things. I''ve developed a system where the "driver" for the graphics system is loaded (in this case, DirectX9) which has calls for "Render", "ClearScreen", "Flip", etc. I have an linked list of iRender states, each representing something different to render (right now, I''m working on rendering a plane). I''m trying to figure out how I would be able to take this and get it into the graphics driver and then render it. I don''t want to have to change the core code in order to render in OpenGL and DirectX, I want the drivers to handle how they are suppose to render things. Here''s my example code: iRender.h
	 class iRender  {
			 iRender(void) { }
			 ~iRender(void) { }

			 virtual void Render(void)=0;
			 virtual void RenderUpdate(void)=0;
			 virtual void Shutdown(void)=0;

			 static void Release(void);
			 static void Update(void);
			 static void Initalize(void);
	 class cRenderPlane : public iRender, public iMObject {
			 cRenderPlane(void) { }
			 virtual ~cRenderPlane(void) { }

			 void Render(void);
			 void RenderUpdate(void);
			 void Shutdown(void);

cDirect3D9.h (different DLL)
 		 class cDirect3D9 : public iVideoDevice {
				 cDirect3D9(void) : iVideoDevice( ) {
					  Base::cLog::Create( );
				 virtual ~cDirect3D9( ) { }

				 bool Initalize(HWND hWnd,RECT rc,bool fullscreen=true);
				 void Release(void);
				 cCamera* GetCamera(void) { return m_pCamera; }
				 void InitCamera(void);

				 int RenderFrame(irender_t &renderList);
				 int ClearScreen(bool bBackBuffer=false);
				 int Flip(void);
				 void ResizeScreen(int iHeight,int iWidth);
				 cCamera* m_pCamera;
				 HWND m_hWnd;
				 IDirect3D9* m_pD3D;
				 IDirect3DDevice9* m_pDevice;
				 IDirect3DSurface9* m_pBackSurface;
				 int m_iHeight;
				 int m_iWidth;
				 float m_fAspectRatio;
I pass the whole list of "render states" into the Render function - right now I don''t do anything in it. I''m trying to figure out how to make a uniform way of doing things in the core engine, and then recgonizing that and rendering it in the drivers when it''s passed. If anyone has any ideas, they''re very welcome! Thanks everyone! -John "bkt" Bellone Flipside Software FlipEngine!

Share this post

Link to post
Share on other sites
Hi John,

I''m doing the same with my project (OS & API independent code). Here''s what I do.

I simply use generic class names and inline wrapper functions and methods for my API and OS stuff. For example, I would change your class name cDirect3D9 (as well as cOpenGL) to cGraphics. That way, you don''t have to change the class and wrapper calls throughout all your source and header files. I would do the same with cWindows, cLinux and cMac, as well, calling all of them something like cOpSys. You''re only using one OS and one API at a time anyway (unless you''re providing the option of DirectX or OpenGL on Windows machines, in which case things could get trickier), so the names do not conflict.

This way, instead of calling cDirect3D9->ClearScreen () you can call cGraphics->ClearScreen ().

If you want to give the user the choice of API like for Windows, maybe you could do an if...else where:

if (API == DirectX)
cDirect3D9 *pGraphics = new cDirect3D9;
cOpenGL *pGraphics = new cOpenGL;

...and with that, just keep all method names and params identical for cOpenGL and cDirect3D9.

Best wishes.

Share this post

Link to post
Share on other sites
Well, it really doesn't matter how I do it (I didn't include that code) I'm using an interface object for the graphics called iVideoDevice* which is a base class for both the graphics objects (cOpenGL and cDirect3D9/cDirect3D8). That's how I am able to load them from seperate DLLs (through my pluggable factory).

I would have included the code, but I guess it really didn't occur to me at the time. Right now Render, Clearscreen, Initalize, GetCamera and a few others are virtual functions from iVideoDevice.

What I am really looking for is an example on how to create a independant rendering objects. What I think I'm going to have to do is create all my math classes, matrix, vector2,vector3,vector4, etc - and then pass them into the renderList which goes right into the render device driver (either opengl or direct3d). Really just looking for an example - but I guess I'll end up figuring it out anyway.

-John "bkt" Bellone
Flipside Software

[edited by - bkt on May 27, 2004 8:07:36 AM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!