Thread: DirectX or OpenGL for older computer

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    DirectX or OpenGL for older computer

    Howdy

    I've been doing C/C++ for about three and a half years now, and I'd like to get into some sort of graphics programming. I have Visual C++ 6.0, but my computer is rather old (350MHz PII, 128mb RAM).

    The graphics I want to create are only 2D, so graphics performance is not much of a problem. I just want to ask which I should learn - DirectX or OpenGL. Which would be easiest to learn and best to use for a bit of 2D graphic games? I would like to learn to do this for Linux as well in the future (so maybe OpenGL), but if DX is easier to learn then that will do fine.

    What do you think?

    Also, does anyone know what the original Starcraft uses? And, any links to eBooks or tutorials on the subject would be awesome.
    Last edited by nickname_changed; 08-30-2003 at 10:09 PM.

  2. #2
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    Either an old version of DirectX (like 7), or OpenGL. You can still develop for older DirectX versions using the current SDK, because it's backwards compatible... you'll just have to look up what the API calls are for the older versions of DirectX, which may or may not be hard. Many people think that OpenGL is easier, too, which it may be. However, DirectX will also handle sound, input, etc. It's you're choice.
    Away.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Sound isn't much of an issue, can OpenGL handle things such as mouse clicks and key presses? OpenGL doesn't sound too bad if its easier to learn, and Quake III runs nicely on this computer so performance problems wont be too bad. But how is OpenGL when it comes to mouse/keyboard input?

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    648
    OpenGL is easier but I like DirectX more because I have more control and its clas structure is more appealing to me. Its naming convention is horrible however but having every component you need in a game, network, sound, music, input, graphics, all in one, is awesome.

  5. #5
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >> But how is OpenGL when it comes to mouse/keyboard input?

    OpenGL is for Graphics only. it does not handle sound/input. There are libraries (such as GLUT) for OpenGL which will do such things.

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, I've been playing around with Direct Draw (seemed the best of the two and I could find plenty of tutorials), and man is this fast!!! I drew 768 bitmaps to the back buffer, flipped, drew another 768 to the back buffer, in an infinite loop, and it looks like the first pic is blended with the second because its drawing so fast!!! Thanks a lot guys!

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, I've got it drawing a few bitmaps. Now I want to know a little about input. Am I supposed to/should I use the WM_MOUSEMOVE message to handle mouse movement, or am I supposed to use Direct Input? If Direct Input is the way, can anyone give me any links to tutorials on the subject?

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    23
    Hi, good to see you're getting along well with it, is dx easy to do and easy to set up with Visual C++? I tried with Dev C++, but got no where. I've foud somewhere I can get Visual C++ for a good price any way so thats ok. Can you just tell us a bit about how you set it up or something
    Cheers

  9. #9
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    I was very lucky because I have a programming friend with ADSL, and he downloaded the DirectX 9 SDK (from microsofts site). I already had VisualC++ installed and I guess the DirectX headers put themselves in when I installed the SDK.

    With DevC++, I guess if you had the SDK and put all the headers/libs into the DevC++ folders, and then told Dev to link with the right .lib files, it could probably work.

  10. #10
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    DirectInput:
    Key codes are DIK_A, DIK_HOME, DIK_PRIOR, etc.

    Here's a DirectInput class ripped from the Two King's tutorials. (Link in the sticky)

    Code:
    #ifndef cinput_h
    #define cinput_h
    
    #include "main.h"
    
    #define D3DFVF_CURSORVERTEX	(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1)
    
    class CInput
    {
    	public:
    		CInput(void);
    		~CInput(void);
    		bool InitDirectInput(void);
    		bool InitKeyboard(void);
    		bool InitMouse(void);
    
    		bool Update(void);
    		bool KeyPressed(int);
    
    		int MouseButtonDown(int index)
    		{
    			if (index<0 || index>NUMMOUSEBUTTONS)
    				return 0;
    			return (m_Button[index]);
    		}
    
    		enum { NUMMOUSEBUTTONS = 3};
    
    		long* GetRelPosition(void) {return m_relposition;}
    
    	private:
    		LPDIRECTINPUT8 m_pDirectInputObject;
    		LPDIRECTINPUTDEVICE8 m_pDirectInputKeyboardDevice,
    									m_pDirectInputMouseDevice;
    
    		char m_KeyBuffer[256];
    		char m_Button[NUMMOUSEBUTTONS];
    		long m_relposition[3];
    
    
    };
    
    #endif
    Code:
    #include "main.h"
    
    CInput::CInput(void)
    {
    	m_pDirectInputObject = NULL;
    	m_pDirectInputKeyboardDevice = NULL;
    
    	if(!InitDirectInput())
    		g_App.SetD3DStatus(false);
    	else if(!InitKeyboard()||!InitMouse())
    		g_App.SetD3DStatus(false);
    }
    
    CInput::~CInput(void)
    {
    	if(m_pDirectInputKeyboardDevice)
    	{
    		m_pDirectInputKeyboardDevice->Unacquire();
    		m_pDirectInputKeyboardDevice->Release();
    		m_pDirectInputKeyboardDevice = NULL;
    	}
    	if(m_pDirectInputMouseDevice)
    	{
    		m_pDirectInputMouseDevice->Unacquire();
    		m_pDirectInputMouseDevice->Release();
    		m_pDirectInputMouseDevice = NULL;
    	}
    	if(m_pDirectInputObject)
    	{
    		m_pDirectInputObject->Release();
    		m_pDirectInputObject = NULL;
    	}
    }
    
    bool CInput::InitDirectInput(void)
    {
    	if(FAILED(DirectInput8Create( GetModuleHandle(NULL),DIRECTINPUT_VERSION, IID_IDirectInput8,
    								(void**)&m_pDirectInputObject,NULL)))
    	{
    		g_Error.Log("DirectInput8Create() failed in CInput::InitDirectInput()");
    		MessageBox(g_App.GetWindowHandle(),"DirectInput8Create() failed!","InitDirectInput()",MB_OK);
    		return false;
    	}
    
    	return true;
    }
    
    bool CInput::InitKeyboard(void)
    {
    	if(FAILED(m_pDirectInputObject->CreateDevice(GUID_SysKeyboard,&m_pDirectInputKeyboardDevice,NULL)))
    	{
    		g_Error.Log("CreateDevice() failed in CInput::InitKeyboard()");
    		MessageBox(g_App.GetWindowHandle(),"CreateDevice() failed!","InitKeyboard()",MB_OK);
    		return false;
    	}
    
    	if(FAILED(m_pDirectInputKeyboardDevice->SetDataFormat(&c_dfDIKeyboard)))
    	{
    		g_Error.Log("SetDataFormat() failed in CInput::InitKeyboard()");
    		MessageBox(g_App.GetWindowHandle(),"SetDataFormat() failed!","InitKeyboard()",MB_OK);
    		return false;
    	}
    
    	if(FAILED(m_pDirectInputKeyboardDevice->SetCooperativeLevel(g_App.GetWindowHandle(),
    							DISCL_BACKGROUND|DISCL_NONEXCLUSIVE)))
    	{
    		g_Error.Log("SetCooperativeLevel() failed in CInput::InitKeyboard()");
    		MessageBox(g_App.GetWindowHandle(),"SetCooperativeLevel() failed!","InitKeyboard()",MB_OK);
    		return false;
    	}
    
    	if(FAILED(m_pDirectInputKeyboardDevice->Acquire()))
    	{
    		g_Error.Log("Acquire() failed in CInput::InitKeyboard()");
    		MessageBox(g_App.GetWindowHandle(),"Acquire() failed!","InitKeyboard()",MB_OK);
    		return false;
    	}
    
    	return true;
    }
    
    bool CInput::InitMouse(void)
    {
    	DIDEVCAPS MouseCapabilities;
    
    	if(FAILED(m_pDirectInputObject->CreateDevice(GUID_SysMouse,&m_pDirectInputMouseDevice,NULL)))
    	{
    		g_Error.Log("CreateDevice() failed in CInput::InitMouse()");
    		MessageBox(g_App.GetWindowHandle(),"CreateDevice() failed!","InitMouse()",MB_OK);
    		return false;
    	}
    	
    	if(FAILED(m_pDirectInputMouseDevice->SetDataFormat(&c_dfDIMouse)))
    	{
    		g_Error.Log("SetDataFormat() failed in CInput::InitMouse()");
    		MessageBox(g_App.GetWindowHandle(),"SetDataFormat() failed!","InitMouse()",MB_OK);
    		return false;
    	}
    
    	if(FAILED(m_pDirectInputMouseDevice->SetCooperativeLevel(g_App.GetWindowHandle(),
    																	DISCL_BACKGROUND|DISCL_NONEXCLUSIVE)))
    	{
    		g_Error.Log("SetCooperativeLevel() failed in CInput::InitMouse()");
    		MessageBox(g_App.GetWindowHandle(),"SetCooperativeLevel() failed!","InitMouse()",MB_OK);
    		return false;
    	}
    
    	if(FAILED(m_pDirectInputMouseDevice->Acquire()))
    	{
    		g_Error.Log("Acquire() failed in CInput::InitMouse()");
    		MessageBox(g_App.GetWindowHandle(),"Acquire() failed!","InitMouse()",MB_OK);
    		return false;
    	}
    
    	MouseCapabilities.dwSize = sizeof(MouseCapabilities);
    	m_pDirectInputMouseDevice->GetCapabilities(&MouseCapabilities);
    	
    	if(!(MouseCapabilities.dwFlags&DIDC_ATTACHED))
    	{
    		g_Error.Log("Mouse is not attached to system.");
    		MessageBox(g_App.GetWindowHandle(),"Mouse is currently not attached!  \nClick here to continue","InitMouse()",MB_OK);
    		return false;
    	}
    
    	return true;
    }
    
    bool CInput::Update(void)
    {
    	if(FAILED(m_pDirectInputKeyboardDevice->GetDeviceState(sizeof(m_KeyBuffer),(LPVOID)&m_KeyBuffer)))
    	{
    		g_Error.Log("GetDeviceState() failed in CInput::Update()");
    		MessageBox(g_App.GetWindowHandle(),"GetDeviceState() failed!","Update()",MB_OK);
    		return false;
    	}
    
    	char done=0;
    	int q;
    	DIMOUSESTATE dims;
    	HRESULT hr;
    
    	memset(&dims,0,sizeof(DIMOUSESTATE));
    	if(!m_pDirectInputMouseDevice) 
    		return false;
    
    	while(!done)
    	{
    		hr=m_pDirectInputMouseDevice->GetDeviceState(sizeof(DIMOUSESTATE),&dims);
    		if (FAILED(hr))
    		{
    			if (hr==DIERR_INPUTLOST||hr==DIERR_NOTACQUIRED)
    			{
    				if (FAILED(m_pDirectInputMouseDevice->Acquire()))
    					done=1;
    			}
    			else
    				done=1;
    		}
    		else
    			done=1;
    	}
    
    	m_relposition[0]=dims.lX;
    	m_relposition[1]=dims.lY;
    	m_relposition[2]=dims.lZ;
    
    	for (q=0;q<NUMMOUSEBUTTONS;q++)
    		m_Button[q]=(dims.rgbButtons[q]&0x80);
    	return true;
    }
    
    bool CInput::KeyPressed(int Key)
    {
    	if(m_KeyBuffer[Key] & 0x80)
    		return true;
    	return false;
    }
    Sorry, I was too lazy to zip that and attach it.
    Away.

  11. #11
    Registered User LogicError's Avatar
    Join Date
    Aug 2003
    Location
    г. Магнитогорск
    Posts
    76
    For 2D Graphics I recommend SDL, and the best part is that SDL supports OpenGL so once you're done with 2D and wanna move on to 3D you can do it all the same http://code3d.gamedev.net

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX vrs. OpenGL - Witch one is better?
    By Queatrix in forum Windows Programming
    Replies: 5
    Last Post: 02-23-2006, 03:32 PM
  2. Allegro, OpenGL.. or even DirectX?
    By Zeusbwr in forum C++ Programming
    Replies: 1
    Last Post: 11-14-2004, 08:16 AM
  3. OpenGL vs DirectX
    By Da-Nuka in forum Game Programming
    Replies: 14
    Last Post: 10-19-2004, 05:23 PM
  4. OpenGL 2 or DirectX ?
    By alex6852 in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 01-02-2003, 02:31 PM
  5. C, DirectX, and OpenGL
    By Spectrum48k in forum C Programming
    Replies: 19
    Last Post: 07-19-2002, 08:23 AM