dcaro69
July 11th, 2007, 03:35 PM
Hey,
I have a rectangle (a piece of memory) that I fill with argb data. I would like to display it in a window, using direct3d. I have 3 questions about that.
1) I've read several tutorials. One solution would be to use the sprite interface. Then create a texture, fill it with data and render it onto the surface. I have written that code:
// the variable d contains a window and d3d object, device and sprite
d->device->Clear (0, NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB (0, 0, 0, 0),
1.0f, 0);
d->device->BeginScene ();
// Here is my argb surface, named 'surf'
w = 64;
h = 64;
depth = 4;
pitch = depth * w;
surf = malloc (depth * w * h);
if (!surf) return 0;
ZeroMemory (surf, depth * w * h);
tmp = (unsigned char *)surf;
for (r = 0; r < w; r++) {
for (g = 0; g < h; g++, tmp += depth) {
tmp[0] = (r * 2 + foo) % 256;
tmp[1] = (g + foo) % 256;
tmp[2] = (w - 1 - g) * 4;
}
}
foo++;
rect.left = 0;
rect.top = 0;
rect.right = w;
rect.bottom = h;
// FIXME : other flags might speed up things
d->sprite->Begin (0);
d->device->CreateTexture (w, h, 0, 0,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&texture, NULL);
// I have to fill the texture with the data of surf
d->sprite->SetTransform (&matrix);
d->sprite->Draw (texture, &rect, NULL, NULL, D3DCOLOR_ARGB (0, 0, 0, 0));
d->sprite->End ();
d->device->EndScene ();
d->device->Present (NULL, NULL, NULL, NULL);
As I mentioned in a comment of that code, I have to fill the texture with the surf data.
I've looked at a lot of tutorials, sites, etc... I didn't find any code to do that. I find code to fill a texture from a file, but not from a piece of memory.
So my first question is: is it possible, and if yes, how ?
2) My second question is about speed. My main cincern is speed. I've already written a code with directdraw 7. The speed is the same than a similar code on linux, using software routines. I don't know if it is normal or not. I wanted to get more speed, so I tried to do that with direct3d, in order to use hardware accelerated features of d3d.
With all the doc and tutorial I've read, I found several things to speed up all that stuff:
a) Using vertices instead of sprites
b) Using the immediate mode of d3d (see here (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnardir3d/html/d3dim.asp))
Is it correct ? and if so, do you have some documentation about vertices or immediate mode, in order to achieve what I want ?
Also, if there are better solutions (that is, faster techniques related to d3d to do what I want), I would be pleased to know them
3) Finally, between opengl and d3d, is there a difference in speed ? (for what I want to do)
thank you very much
Vincent Torri
I have a rectangle (a piece of memory) that I fill with argb data. I would like to display it in a window, using direct3d. I have 3 questions about that.
1) I've read several tutorials. One solution would be to use the sprite interface. Then create a texture, fill it with data and render it onto the surface. I have written that code:
// the variable d contains a window and d3d object, device and sprite
d->device->Clear (0, NULL,
D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_ARGB (0, 0, 0, 0),
1.0f, 0);
d->device->BeginScene ();
// Here is my argb surface, named 'surf'
w = 64;
h = 64;
depth = 4;
pitch = depth * w;
surf = malloc (depth * w * h);
if (!surf) return 0;
ZeroMemory (surf, depth * w * h);
tmp = (unsigned char *)surf;
for (r = 0; r < w; r++) {
for (g = 0; g < h; g++, tmp += depth) {
tmp[0] = (r * 2 + foo) % 256;
tmp[1] = (g + foo) % 256;
tmp[2] = (w - 1 - g) * 4;
}
}
foo++;
rect.left = 0;
rect.top = 0;
rect.right = w;
rect.bottom = h;
// FIXME : other flags might speed up things
d->sprite->Begin (0);
d->device->CreateTexture (w, h, 0, 0,
D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT,
&texture, NULL);
// I have to fill the texture with the data of surf
d->sprite->SetTransform (&matrix);
d->sprite->Draw (texture, &rect, NULL, NULL, D3DCOLOR_ARGB (0, 0, 0, 0));
d->sprite->End ();
d->device->EndScene ();
d->device->Present (NULL, NULL, NULL, NULL);
As I mentioned in a comment of that code, I have to fill the texture with the surf data.
I've looked at a lot of tutorials, sites, etc... I didn't find any code to do that. I find code to fill a texture from a file, but not from a piece of memory.
So my first question is: is it possible, and if yes, how ?
2) My second question is about speed. My main cincern is speed. I've already written a code with directdraw 7. The speed is the same than a similar code on linux, using software routines. I don't know if it is normal or not. I wanted to get more speed, so I tried to do that with direct3d, in order to use hardware accelerated features of d3d.
With all the doc and tutorial I've read, I found several things to speed up all that stuff:
a) Using vertices instead of sprites
b) Using the immediate mode of d3d (see here (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnardir3d/html/d3dim.asp))
Is it correct ? and if so, do you have some documentation about vertices or immediate mode, in order to achieve what I want ?
Also, if there are better solutions (that is, faster techniques related to d3d to do what I want), I would be pleased to know them
3) Finally, between opengl and d3d, is there a difference in speed ? (for what I want to do)
thank you very much
Vincent Torri