Jump to content

  • Log In with Google      Sign In   
  • Create Account

Creating dynamic? textures.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 02:34 AM

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, 24 February 2014 - 02:35 AM.


Sponsor:

#2 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 03:39 AM

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, 24 February 2014 - 05:25 AM.


#3 Hodgman   Moderators   -  Reputation: 31799

Like
1Likes
Like

Posted 24 February 2014 - 05:57 AM

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[...] = ...



#4 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 03:12 PM

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, 24 February 2014 - 03:14 PM.


#5 Buckeye   Crossbones+   -  Reputation: 6251

Like
0Likes
Like

Posted 24 February 2014 - 03:30 PM

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, 24 February 2014 - 03:31 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#6 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 03:34 PM


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.

#7 Buckeye   Crossbones+   -  Reputation: 6251

Like
1Likes
Like

Posted 24 February 2014 - 03:45 PM

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, 24 February 2014 - 03:51 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#8 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 03:54 PM

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

#9 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 03:58 PM

Now I am failing at the LockRect() call in my draw loop (0x8876086C - seems like some sort of generic error)

#10 Buckeye   Crossbones+   -  Reputation: 6251

Like
1Likes
Like

Posted 24 February 2014 - 04:02 PM

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, 24 February 2014 - 04:05 PM.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.


#11 DarkRonin   Members   -  Reputation: 616

Like
0Likes
Like

Posted 24 February 2014 - 04:10 PM

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, 24 February 2014 - 04:10 PM.


#12 greenpig83   Members   -  Reputation: 326

Like
0Likes
Like

Posted 25 February 2014 - 03:39 PM

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!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS