Sign in to follow this  

Problem displaying images.

This topic is 3290 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

Hi again. I am trying to show up 10 sprites taken of a "sprites.bmp" file, in the project folder, to the screen, but I get some errors. The code I think the errors come from is:
VOID Render()
{
	IDirect3DSurface9* surface		 ;
	IDirect3DSurface9* spriteSurface ;
	IDirect3DSurface9* backbuffer	 ;
	if (NULL==g_pd3dDevice)
		return;

	hResult=g_pd3dDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
	if (FAILED(hResult))
		return;
	spriteSurface=getSurfaceFromBitmap("sprites.bmp");
	
	//Clear the backbuffer to a blue color
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 200, 255), 1.0f, 0);

	//Get the backbuffer
	g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //Here we get a pointer to the backbuffer surface
	//Copy the offscreen(surface) to the backbuffer
	for (int i = 10; i<10; i++)
	{
		RECT destRect; //Temporary destination rect
		//Fill the temporary rect with data from the current sprite structure
		destRect.left	=	spriteStruct[i].srcRect.left				 ;
		destRect.top	=	spriteStruct[i].srcRect.top					 ;
		destRect.bottom =	spriteStruct[i].srcRect.top  + SPRITE_HEIGHT ;
		destRect.right  =	spriteStruct[i].srcRect.left + SPRITE_WIDTH  ;

		//Draw the sprite to the backbuffer
		g_pd3dDevice->StretchRect(spriteSurface,
								  &spriteStruct[i].srcRect,
								  backbuffer,
								  &destRect,
								  D3DTEXF_NONE);
	}

//	if (SUCCEEDED(g_pd3dDevice->BeginScene()))
//	{
		//rendering of scene objects can happen here

		//End the scene
//		g_pd3dDevice->EndScene();
//	}

	//Present the backbuffer contents to the display
	g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

IDirect3DSurface9* getSurfaceFromBitmap(std::string filename)
{
	HRESULT			   hResult = NULL;
	IDirect3DSurface9* surface = NULL;
	D3DXIMAGE_INFO	   imageInfo	 ; //holds details concerning this bitmap

	//Get the width and height info from this bitmap
	hResult=D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);

	//Make sure that the call to D3DXGetImageInfoFromFile was succeeded
	if (FAILED(hResult))
		return NULL;

	//Create the offscreen surface that will hold the bitmap
	hResult=g_pd3dDevice->CreateOffscreenPlainSurface(800, 600, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
	if (FAILED(hResult))
		return NULL;

	//Load the bitmap into the surface
	hResult=D3DXLoadSurfaceFromFile(surface,
									NULL,
									NULL,
									filename.c_str(),
									NULL,
									D3DX_DEFAULT,
									0,
									NULL);

	if (FAILED(hResult))
		return NULL;

	return surface;
}

bool initSprites(void)
{
	//Loop through 10 sprite structures and initialize them
	for (int i = 0; i < 10; i++)
	{
		spriteStruct[i].srcRect.top    = 0										     ;
		spriteStruct[i].srcRect.left   = i * SPRITE_WIDTH						     ;
		spriteStruct[i].srcRect.right  = spriteStruct[i].srcRect.left + SPRITE_WIDTH ;
		spriteStruct[i].srcRect.bottom = SPRITE_HEIGHT						         ;

		spriteStruct[i].posX		   = rand() % SCRN_WIDTH  - SPRITE_WIDTH		 ;
		spriteStruct[i].posY		   = rand() % SCRN_HEIGHT - SPRITE_HEIGHT		 ;
	}
	return true;
}
The errors say:
Sprites_Direct3D error LNK2020: simbol (token) without solving (0A00000A) spriteStruct

Sprites_Direct3D fatal error LNK1120: 1 extern without solving
Why do I get this errors? Is there any mistake in code? And yes, I included the link dependencies with lines:
#pragma comment(lib,"d3d9.lib");
#pragma comment(lib,"d3dx9.lib");
Thank you for attention. Ah! I almost forget it! Do you know any code colorizer, to make reading codes clearer and easier? Thank you! EDIT: Gave your thread a title, replaced large code tag with source tag. -jba. [Edited by - jbadams on December 8, 2008 9:33:26 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by darkcube
I am using Microsoft Visual Studio .NET, and yes, it does colorizes the text, but at time of copying into post, colors dissapear.

What can I do whit the problem above?

Thank you,

Skinner


You should use "source" tag.
For more information see FAQ.

Sample:

#include <iostream>

int main(int argc, char * argv[])
{
std::cout << "Hello World!" << std::endl;
return 0;
}



Share this post


Link to post
Share on other sites
Quote:
Original post by darkcube
I am using Microsoft Visual Studio .NET, and yes, it does colorizes the text, but at time of copying into post, colors dissapear.

What can I do whit the problem above?

Thank you,

Skinner
You haven't implemented spriteStruct anywhere, the linker doesn't know where to find it. You have a declaration, but no implementation.

As for the code-colouriser, just use [ source ] tags instead of [ code ]

Share this post


Link to post
Share on other sites
Quote:
Original post by darkcube
Ah! I almost forget it! Do you know any code colorizer, to make reading codes clearer and easier?
Hi,

I edited your post to give the thread a descriptive title (rather than being listed as "untitled" as it was originally posted) and to replace the code tags around your largest segment of code with source tags as described in this section of the forum FAQ. You can hit the edit button on your post if you'd like to see the change I made (as a side-note, you can also do this to other user's posts to see how they've posted in a certain style, you just won't be able to submit changes).

Carry on folks! [smile]

Share this post


Link to post
Share on other sites
Thank you jbadams :)
Quote:
Original post by Evil Steve
Quote:
Original post by darkcube
I am using Microsoft Visual Studio .NET, and yes, it does colorizes the text, but at time of copying into post, colors dissapear.

What can I do whit the problem above?

Thank you,

Skinner
You haven't implemented spriteStruct anywhere, the linker doesn't know where to find it. You have a declaration, but no implementation.

As for the code-colouriser, just use [ source ] tags instead of [ code ]


Hey Evil Steve. I did implemented the spriteStruct. Here is the whole code:


//To convert an aplication from WINDOWED mode, to FULL SCREEN mode:
//1. Change WS_OVERLAPPEDWINDOW to WS_EX_TOPMOST | WS_POPUP | WS_VISIBLE
//2. d3dpp.backbufferformat=D3DFMT_X8R8G8B8
//3. d3dpp.windowed=FALSE

//In this example, we encompass all needed functions to another one, called getSurfaceFromBitmap

#include <windows.h>
#include <string>
#include <d3d9.h>
#include <d3dx9.h>
#include "resource.h"

#pragma comment(lib,"d3d9.lib"); //Link dependencies: instead of Project -> Properties -> Linker
#pragma comment(lib,"d3dx9.lib"); //Link dependencies: instead of Project -> Properties -> Linker

//GLOBAL VARIABLES
HINSTANCE g_hInstance = 0;
HWND g_hWnd = 0;
LPDIRECT3D9 g_pD3D = 0;
LPDIRECT3DDEVICE9 g_pd3dDevice = 0;
HRESULT hResult = 0;
#define SPRITE_WIDTH 48
#define SPRITE_HEIGHT 48
#define SCRN_WIDTH 640
#define SCRN_HEIGHT 480
struct {
RECT srcRect;
//Position
int posX;
int posY;
} spriteStruct[];

//Function prototypes
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
HRESULT InitD3D( HWND hWnd );
VOID Cleanup();
VOID Render();
IDirect3DSurface9* getSurfaceFromBitmap(std::string filename);
bool initSprites(void);


//WinMain
INT WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)
{
//Save handle
g_hInstance = hInstance;

//Fill out a WNDCLASS structure
WNDCLASS wc;
wc.lpfnWndProc=WndProc;
wc.style=CS_HREDRAW|CS_VREDRAW;
wc.lpfnWndProc=WndProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hbrBackground=(HBRUSH)::GetStockObject(BLACK_BRUSH);
wc.hIcon=::LoadIcon(0, IDI_APPLICATION);
wc.hCursor=::LoadCursor(0, IDC_ARROW);
wc.hInstance=g_hInstance;
wc.lpszMenuName=0;
wc.lpszClassName="WindowA";

//Register our WNDCLASS structure (wc)
RegisterClass( &wc );

//Create the window
g_hWnd=::CreateWindow("WindowA", "Title bar", WS_OVERLAPPEDWINDOW, 0, 0, 800, 600, 0, 0, g_hInstance, 0);
if (g_hWnd == 0)
{
MessageBox(0, "Create window - FAILED", "ERROR", MB_OK);
return false;
}
if (SUCCEEDED(InitD3D(g_hWnd)))
{
//Show and update the window
ShowWindow(g_hWnd, showCmd);
UpdateWindow(g_hWnd);

//Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof(msg) );

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
return 0;
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
case WM_LBUTTONDOWN:
MessageBox (0, "You pressed the left button!", "LEFT CLIC", MB_OK);
return 0;

case WM_KEYDOWN:
if (wParam == VK_ESCAPE)
{
if ((MessageBox(g_hWnd, "Would you like to exit?", "Exit", MB_YESNO + MB_DEFBUTTON2)==IDYES))
DestroyWindow(g_hWnd);
}
return 0;

case WM_PAINT:
Render();
ValidateRect(g_hWnd, NULL);
return 0;

case WM_DESTROY:
Cleanup();
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}

HRESULT InitD3D( HWND hWnd )
{
//Create the D3D Object, needed to create the device.
if (NULL ==(g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return false;

D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = g_hWnd;

if (FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice)))
return E_FAIL;

return S_OK;
}

VOID Cleanup()
{
if (g_pd3dDevice != NULL)
g_pd3dDevice->Release();
if (g_pD3D != NULL)
g_pD3D->Release();
}

VOID Render()
{
IDirect3DSurface9* surface ;
IDirect3DSurface9* spriteSurface ;
IDirect3DSurface9* backbuffer ;
if (NULL==g_pd3dDevice)
return;

hResult=g_pd3dDevice->CreateOffscreenPlainSurface(640, 480, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if (FAILED(hResult))
return;
//hResult=D3DXLoadSurfaceFromFile(surface, NULL, NULL, "test.bmp", NULL, D3DX_DEFAULT, 0, NULL);
//if (FAILED(hResult))
// return;
spriteSurface=getSurfaceFromBitmap("sprites.bmp");

//Clear the backbuffer to a blue color
g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100, 200, 255), 1.0f, 0);

//Get the backbuffer
g_pd3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer); //Here we get a pointer to the backbuffer surface
//Copy the offscreen(surface) to the backbuffer
for (int i = 10; i<10; i++)
{
RECT destRect; //Temporary destination rect
//Fill the temporary rect with data from the current sprite structure
destRect.left = spriteStruct[i].srcRect.left ;
destRect.top = spriteStruct[i].srcRect.top ;
destRect.bottom = spriteStruct[i].srcRect.top + SPRITE_HEIGHT ;
destRect.right = spriteStruct[i].srcRect.left + SPRITE_WIDTH ;

//Draw the sprite to the backbuffer
g_pd3dDevice->StretchRect(spriteSurface,
&spriteStruct[i].srcRect,
backbuffer,
&destRect,
D3DTEXF_NONE);
}

// if (SUCCEEDED(g_pd3dDevice->BeginScene()))
// {
//rendering of scene objects can happen here

//End the scene
// g_pd3dDevice->EndScene();
// }

//Present the backbuffer contents to the display
g_pd3dDevice->Present(NULL, NULL, NULL, NULL);
}

IDirect3DSurface9* getSurfaceFromBitmap(std::string filename)
{
HRESULT hResult = NULL;
IDirect3DSurface9* surface = NULL;
D3DXIMAGE_INFO imageInfo ; //holds details concerning this bitmap

//Get the width and height info from this bitmap
hResult=D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);

//Make sure that the call to D3DXGetImageInfoFromFile was succeeded
if (FAILED(hResult))
return NULL;

//Create the offscreen surface that will hold the bitmap
hResult=g_pd3dDevice->CreateOffscreenPlainSurface(800, 600, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
if (FAILED(hResult))
return NULL;

//Load the bitmap into the surface
hResult=D3DXLoadSurfaceFromFile(surface,
NULL,
NULL,
filename.c_str(),
NULL,
D3DX_DEFAULT,
0,
NULL);

if (FAILED(hResult))
return NULL;

return surface;
}

bool initSprites(void)
{
//Loop through 10 sprite structures and initialize them
for (int i = 0; i < 10; i++)
{
spriteStruct[i].srcRect.top = 0 ;
spriteStruct[i].srcRect.left = i * SPRITE_WIDTH ;
spriteStruct[i].srcRect.right = spriteStruct[i].srcRect.left + SPRITE_WIDTH ;
spriteStruct[i].srcRect.bottom = SPRITE_HEIGHT ;

spriteStruct[i].posX = rand() % SCRN_WIDTH - SPRITE_WIDTH ;
spriteStruct[i].posY = rand() % SCRN_HEIGHT - SPRITE_HEIGHT ;
}
return true;
}



What's wrong with the code?? :S

Thank you :)

Skinner



Share this post


Link to post
Share on other sites

This topic is 3290 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this