PutPixel is undefined?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
KPence
Posts: 18
Joined: April 21st, 2012, 12:18 am

PutPixel is undefined?

Post by KPence » April 21st, 2012, 1:12 am

Image
^From Game.cpp in the game class

After doing the changes to putpixel in lesson 13, it won't work anymore and is underlined in red.

Code: Select all

/****************************************************************************************** 
 ******************************************************************************************/
#include "D3DGraphics.h"

D3DGraphics::D3DGraphics( HWND hWnd )
{
	backRect.pBits = NULL;
	pDirect3D = Direct3DCreate9( D3D_SDK_VERSION );

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp,sizeof( d3dpp ) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

    pDirect3D->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,&d3dpp,&pDevice );

	pDevice->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO,&pBackBuffer );
}

D3DGraphics::~D3DGraphics()
{
	if( pDevice )
	{
		pDevice->Release();
		pDevice = NULL;
	}
	if( pDirect3D )
	{
		pDirect3D->Release();
		pDirect3D = NULL;
	}
	if( pBackBuffer )
	{
		pBackBuffer->Release();
		pBackBuffer = NULL;
	}
}

void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
	((D3DCOLOR*)backRect.pBits)[ x + (backRect.Pitch >> 2) * y ] = D3DCOLOR_XRGB( r,g,b );
}


void D3DGraphics::BeginFrame()
{
	pDevice->Clear( 0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),0.0f,0 );
	pBackBuffer->LockRect( &backRect, NULL,NULL);
}

void D3DGraphics::EndFrame()
{
	pBackBuffer->UnlockRect();
	pDevice->Present( NULL,NULL,NULL,NULL );
}
Did I mess something up?

Code: Select all

1>------ Build started: Project: Chili DirectX Framework, Configuration: Debug Win32 ------
1>Build started 4/20/2012 8:13:47 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\Chili DirectX Framework.unsuccessfulbuild".
1>ClCompile:
1>  Game.cpp
1>c:\users\kyle pence\documents\visual studio 2010\projects\chili directx framework\assets\game.cpp(67): error C3861: 'PutPixel': identifier not found
1>c:\users\kyle pence\documents\visual studio 2010\projects\chili directx framework\assets\game.cpp(93): warning C4244: 'initializing' : conversion from 'float' to 'int', possible loss of data
1>c:\users\kyle pence\documents\visual studio 2010\projects\chili directx framework\assets\game.cpp(94): error C3861: 'PutPixel': identifier not found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.52
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Needs more foo

Dlotan
Posts: 32
Joined: April 10th, 2012, 4:58 pm

Re: PutPixel is undefined?

Post by Dlotan » April 21st, 2012, 1:17 am

its a member function of the gfx class, so the function gets called by sayin

gfx.PutPixel(...);

KPence
Posts: 18
Joined: April 21st, 2012, 12:18 am

Re: PutPixel is undefined?

Post by KPence » April 21st, 2012, 1:18 am

Thank you! I was trying to do "D3DGraphics." instead of "gfx." earlier, lol thank you!
Needs more foo

Dlotan
Posts: 32
Joined: April 10th, 2012, 4:58 pm

Re: PutPixel is undefined?

Post by Dlotan » April 21st, 2012, 1:19 am

np buddy ;)

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: PutPixel is undefined?

Post by chili » April 21st, 2012, 5:47 am

Thanks as always Dlotan :)
Chili

error
Posts: 1
Joined: June 16th, 2012, 4:23 pm

Re: PutPixel is undefined?

Post by error » June 16th, 2012, 4:32 pm

:( :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry: :(
I was hoping that post would help me, but it is not the same problem, just near it...

After the PutPixel change my game crashes everytime i debug and i have no idea why, i just watched the video 10 times and remade the code, and every time its the same thing, the build solution is just fine, it do not detects any problem, but when i debug it crashes and says:

Unhandled exception at 0x008a1882 in Chili DirectX Framework.exe: 0xC0000005: Access violation writing location 0x0000056c.

Trying to explore the debug, it just says me anything is wrong at:

" ((D3DCOLOR*)backRect.pBits)[ x + (backRect.Pitch >> 2) * y ] = D3DCOLOR_XRGB( r,g,b );"

The code is:

.h

Code: Select all

#pragma once

#include <d3d9.h>

class D3DGraphics
{
public:
	D3DGraphics( HWND hWnd );
	~D3DGraphics();
	void PutPixel( int x,int y,int r,int g,int b );
	void BeginFrame();
	void EndFrame();
private:
	IDirect3D9*			pDirect3D;
	IDirect3DDevice9*	pDevice;
	IDirect3DSurface9*  pBackBuffer;
	D3DLOCKED_RECT		backRect;
};
.cpp

Code: Select all

#include "D3DGraphics.h"

D3DGraphics::D3DGraphics( HWND hWnd )
{
	backRect.pBits = NULL;

	pDirect3D = Direct3DCreate9( D3D_SDK_VERSION );

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp,sizeof( d3dpp ) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

    pDirect3D->CreateDevice( D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE,&d3dpp,&pDevice );

	pDevice->GetBackBuffer( 0,0,D3DBACKBUFFER_TYPE_MONO,&pBackBuffer );
}

D3DGraphics::~D3DGraphics()
{
	if( pDevice )
	{
		pDevice->Release();
		pDevice = NULL;
	}
	if( pDirect3D )
	{
		pDirect3D->Release();
		pDirect3D = NULL;
	}
	if( pBackBuffer )
	{
		pBackBuffer->Release();
		pBackBuffer = NULL;
	}
}

void D3DGraphics::PutPixel( int x,int y,int r,int g,int b )
{
	((D3DCOLOR*)backRect.pBits)[ x + (backRect.Pitch >> 2) * y ] = D3DCOLOR_XRGB( r,g,b );
}

void D3DGraphics::BeginFrame()
{
	pDevice->Clear( 0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0),0.0f,0 );
	pBackBuffer->LockRect( &backRect,NULL,NULL );
}

void D3DGraphics::EndFrame()
{
	pBackBuffer->UnlockRect();
	pDevice->Present( NULL,NULL,NULL,NULL );
}
Please, i'm completly desperate, just tried to fix that tons of times!

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

Re: PutPixel is undefined?

Post by LuX » June 16th, 2012, 5:00 pm

Can't say much with just the D3DGraphics. Looking at the error you most likely are drawing outside the screen. Do you have anything written in "Game"?

Also, it's a ton easier to fix something if you post the whole project here. After reading the "READ THIS FIRST!" post.
ʕ •ᴥ•ʔ

User avatar
magusofmirrors
Posts: 56
Joined: May 12th, 2012, 10:03 pm

Re: PutPixel is undefined?

Post by magusofmirrors » June 16th, 2012, 6:59 pm

Dlotan, gfx is not a class. D3DGraphics is the class, while gfx is an instance of the class. Unless if it were a static function (amiright? chili?), you can't call a function without an instance. And yes, LUX, I also believe he is trying to draw out of the screen. Remember, error, the dimensions of the window is like 800x600.
The admins are coming!!!

Image

Post Reply