• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lonewolff

Creating dynamic? textures.

11 posts in this topic

Hi Guys,

 

Just wondering if I could get some guidance on creating dynamic textures (I think that is the term) for something that is in memory.

 

If I have a pointer to the start of a pure RGBA stream, how could I make this into a texture to display on a sprite?

 

I have all the framework ready for this and am using a texture from a file, but just wanting to try something different here.

 

Many thanks in advance smile.png

Edited by lonewolff
0

Share this post


Link to post
Share on other sites

OK, I am close. I am upto the point where I need to copy the data back. I have a locked rect. But not sure how to do this properly.
 
I have this, bit it is throwing a bunch of compiler errors;
 
There is a RAW bitmap starting at bmpTmp that I am trying to send to the texture.

mRenderer->textureVideoGet()->LockRect(0,&lockedRect,&rect,0);
 
for(i=0;i<(videoWidth*videoHeight*3);i+=3)
{
	idx=(x*4)+y*lockedRect.Pitch*4;
 
	lockedRect.pBits[idx]=bmpTmp[i]; //b
	lockedRect.pBits[idx+1]=bmpTmp[i+1]; //g
	lockedRect.pBits[idx+2]=bmpTmp[i+2]; //r
	lockedRect.pBits[idx+3]=255; //a
 
	x++;
	if(x>=videoWidth)
	{
		x=0;
		y--;
		if(y<0)
			y=0;
	}
}

mRenderer->textureVideoGet()->UnlockRect(0);

 
The errors I am getting are these (one set each for each lockedRect.pBits line);
 
error C2036: 'void *' : unknown size
error C2120: 'void' illegal with all types
 
Any help would be great!
 
Thanks in advance smile.png

Edited by lonewolff
0

Share this post


Link to post
Share on other sites

You need to cast it to an array of bytes, as a void* (array of nothings) has no type, so you can't assign void values, and you can't use the [] operator.

 

Just add this right after the LockRect line:

unsigned char* bytes = (unsigned char*)lockedRect.pBits;

 

and then replace lockedRect.pBits[...] = ...

with bytes[...] = ...

1

Share this post


Link to post
Share on other sites
Thanks Hodgman, compiles fine now. But, all I get is a black screen that is flickering my framerate counter (FPS is the last thing drawn in the render process).
 
I am not getting any errors from (FAILED) though.
 
This is my draw call. I have simplified it for debugging purposes, so in theory I should get a shot blue line rendered (if I am correct).
 
RECT rect={0,640,0,480};
D3DLOCKED_RECT lockedRect={0};

hr=mRenderer->textureVideoGet()->LockRect(0,&lockedRect,&rect,0);
if(FAILED(hr))
{
	std::cout<<"Error: "<<hr<<"\r\n";
	system("PAUSE");
	return 0;
}

unsigned char* bytes=(unsigned char*)lockedRect.pBits;

for(i=0;i<20;i=i+4)
{
	bytes[i]=255;
	bytes[i+1]=0;
	bytes[i+2]=0;
	bytes[i+3]=255;
}

mRenderer->textureVideoGet()->UnlockRect(0);

// render the sprite queue
mRenderer->renderSpriteQueue();

// display framerate data
lps=mRenderer->framerateGetReal();
lps=lps-1;
if(lps<0)
	lps=0;

itoa(lps,szBuffer,10);
strcpy(szBuffer2,"Frame Rate: ");
strcat(szBuffer2,szBuffer);
strcat(szBuffer2," FPS");
mRenderer->renderDebugText(14,14,szBuffer2);

Is it something to do with how I am creating the texture?
 
// Sprite renders ok with this texture
if(FAILED(D3DXCreateTextureFromResourceA(d3dDevice,GetModuleHandle(NULL),MAKEINTRESOURCE(IDB_PNG1),&pTexture)))
	MessageBox(0,"Can not find file","Resource not found",0);

// Sprite won't work with this texture
if(FAILED(D3DXCreateTexture(d3dDevice,1024,1024,0,NULL,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&pVideoTexture))) 
	MessageBox(0,"Can not create blank video texture","Resource not found",0);

Any additional help would be awesome.

BTW, I am a newbie when it comes to dynamic textures and locking (never done it before). Edited by lonewolff
0

Share this post


Link to post
Share on other sites
for(i=0;i<20;i=i+4)
{
    bytes[i]=255;
    bytes[i+1]=0;
    bytes[i+2]=0;
    bytes[i+3]=255;
}

Unless I'm missing something, you're only setting 5 pixels. Is that your intent?

Edited by Buckeye
0

Share this post


Link to post
Share on other sites

for(i=0;i<20;i=i+4)
{
    bytes[i]=255;
    bytes[i+1]=0;
    bytes[i+2]=0;
    bytes[i+3]=255;
}
Unless I'm missing something, you're only setting 5 pixels. Is that your intent?


Yes, for the moment (for debugging purposes until I can get something on the screen.

I found that I should probably be using D3DUSAGE_DYNAMIC in my texture creation. So, I have changed my texture creation call to this;

if(FAILED(D3DXCreateTexture(d3dDevice,1024,1024,0,D3DUSAGE_DYNAMIC,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,&pVideoTexture))) 
	MessageBox(0,"Can not create blank video texture","Resource not found",0);

But, now my application fails at this call.
0

Share this post


Link to post
Share on other sites

The docs say you can't create a texture in D3DPOOL_MANAGED.

 

What error are you getting? What does the debug output provide?

 

Before you try D3DPOOL_DEFAULT, check your devcaps to ensure you can support the texture parameters.

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

The docs say you can't create a texture in D3DPOOL_MANAGED.
 
What error are you getting? What does the debug output provide?
 
Before you try D3DPOOL_DEFAULT, check your devcaps to ensure you can support the texture parameters.


Ooooh, Thanks man. I have changed to D3DPOOL_DEFAULT and it gets past that error. Still not working as I am after yet, but still a step closer ;)

I'll do some more checking now that I am over that hurdle and get back to you smile.png
0

Share this post


Link to post
Share on other sites

The DirectX control panel should have a utility for error codes. At a minimum, you can use DXGetErrorString or DXGetErrorDescription.

 

At best, compile with debug, use the debug libraries, and set the DirectX control panel to maximum reporting.

 

Actually, "best" would be to read the docs, look for examples, etc. There've been a lot of posts here on gamedev about similar problems.

Edited by Buckeye
1

Share this post


Link to post
Share on other sites

Actually, "best" would be to read the docs, look for examples, etc. There've been a lot of posts here on gamedev about similar problems.


Thanks man. But, I have actually been reading up on this for days and days now, with no huge progress.

I actually got it behaving correctly just then by changing my LockedRect call to this...

hr=mRenderer->textureVideoGet()->LockRect(0,&lockedRect,NULL,0);

...making the third parameter NULL (the area to lock). So, I guess I am now locking the whole image? Not sure why it doesn't work if I specify a rect though. Odd.

But, I am now seeing a 5 pixel white line (as intended). Edited by lonewolff
0

Share this post


Link to post
Share on other sites

Using D3DPOOL_MANAGED is nice because when you reset your graphic  (fullscreen ->windows, change resolution...) you dont have to worry about the Texture. Otherwise you will have to relase and recreate all the texture you loaded!

0

Share this post


Link to post
Share on other sites

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  
Followers 0