Direct3D - Blitting Surfaces instead of Textures? (Mostly Solved)

Started by
8 comments, last by deadimp 18 years, 10 months ago
[I'm probably going to have MANY more questions with Direct3D, I've only began true D3D programming today] Question #1: Is there some way to blit a surface to Direct3D's render target without having to copy bitmap memory from the surface to a texture? What I'm trying to do is draw on a surface, and then draw that surface at a certain position on the screen. *NOT YET TESTED SUCCESSFULLY* NOTE: The next questions aren't really as important as the first one Question #2: What is the most efficient method for drawing ellipses? Should I calculate all of the points and put them in a vertex buffer, or does Direct3D have an easier way? *SOLVED* Question #3: What is the most efficient/easy method for drawing text? Blitting text on a surface with TextOut using WinGDI, using the D3DX class, making my own...? *NOT YET ATTEMPTED* Question #4: How would I imitate a pen in WinGDI using D3D? Do I draw a D3DPT_LINELIST primitive over my filled primitive, or does D3D have something more to offer there also? Plus, how do you change line thickness? What methods are there. *NOT YET ATTEMPTED* [Edited by - deadimp on June 14, 2005 9:06:59 PM]
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Advertisement
#2: I'm not positive it's the most efficient way, but that's how I've always drawn ellipses, never heard of a better one anyway.

#3: It depends a little on what you want to do. The D3DX class is probably the easiest way, but it doesn't offer antialiasing. Making your own class would let you do that. I'm not totally sure about WinGDI, but as I understand it it's basically slower at everything.

#4. If you want thick lines, D3DX has a line class that lets you draw a list of vertices. You can change it's thickness and even antialias it, although when using it to draw curvy lines (like the ellipse) I've always gotten artifacts, couldn't figure out how to get rid of them. If you want a really perfect thick line, I think the only way to do it is to draw it with triangles. Also, I don't think the D3DX line class is particularly fast, so use at own risk.

Hope that helps.

Max
--------------Trans2D - 2D library for C# / Managed DirectX
I've been browsing around the MSDN some, and the tutorial I've been using, and I found the function IDirect3DTexture8::GetSurfaceLevel(). However, I'm not sure I will be able to draw on the surface after I start beginning and ending scenes and such. Will that actually affect anything?
<br><br>Also, what exactly are artifacts?
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
The only ways of drawing on surfaces I know are using a RenderToSurface (don't know what it's called in the C++ API) and texture shaders, though I think I've seen examples of people locking a texture and writing to it before. I don't think you can have a RTS scene during a regular device scene, but I don't see why you'd want to.

"Artifacts" just means little graphical problems, like if an image was slightly distorted or something. In particular, I was referring to small areas of my ellipses that don't get drawn. It's clear why this happens: the lines are essentially rotated rectangles, so their corners don't meet up nicely.



If you used a set of vertices around both the inner and outer radii of the circle, this would not be an issue, and it's barely more difficult to do. Hell, might even be faster since you aren't using the D3DX line class. Of course, you lose antialiasing, though if you wanted I think you could sort of do it by using four rings of vertices, with the outermost two having alpha values of zero.
--------------Trans2D - 2D library for C# / Managed DirectX
I want to do this to implicate the use of views. You see, for each view, the room cycles through each object that is registered in it, and draws it on the current view, or renders it in this case. That is why I need it. If I can't do something super-efficient, I might as well go with the memory copying part because before I merely had it BitBlt the view's HDC to the DirectDraw backbuffer. Fun stuff.
I'll try it out and do something else if it doesn't work out... *Breaks down and sobs*
As for the line thickness, anti-aliasing doesn't really matter to me. How exactly would I go about making vertices on the inner and outer edges?
Thanks for your help so far.
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Well, I've got a basic function for drawing ellipses. Does this seem right?
bool draw_ellipse(long x1, long y1, long x2, long y2,D3DCOLOR *colors,DGIC_FLAG flags) { view_align(x1,y1,x2,y2); if (colors==NULL) { colors=&brush_color; flags=DGIC_COL1; } //Fun shtuff right heeyah float cx, cy, rx, ry; rx=(x2-x1)/2; ry=(y2-y1)/2; //Skip the uber complicated stuff cx=x1+rx; cy=y1+ry; //I don't think Ramanujan'll slap me for this (http://www.csgnetwork.com/mthcircumellipse.html) ULONG points=pi*2*sqrt((rx*rx+ry*ry)/2); //Eep... floating point fun, here I come. Yippee. float angle=0, astep=(pi*2)/points; vector<D3DCUSTOMVERTEX> vPoints; D3DCUSTOMVERTEX vPoint={cx,cy,0.0f,1.0f,*colors}; vPoints.push_back(vPoint); //Add center point for (ULONG i=0;i<points;i++) {  vPoint.x=cx+(rx*cos(angle)); vPoint.y=cy-(ry*sin(angle));  if (flags & DGIC_COL2) vPoint.color=colors[1];  else vPoint.color=*colors;  vPoints.push_back(vPoint);  angle+=astep; } D3DMakeVertexBuffer(vPoints); //Mah functions return D3DDrawVertexPrimitive(D3DDVP_ELLIPSE,points+1); //Remember center point}

NOTE: Ignore the comments, I wrote them while I was crazy, and don't bother about the flags and such
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Your ellipse code looks fine. If you wanted to do thickness using triangles, you'd make a vertex buffer with twice as many vertices as you have now, and at each iteration of the loop create two points: one at radius-thickness/2, another at radius+thickness/2. Render it as a triangle strip.

Just remember that it is your -actual radius- that you have to increase by thickness/2, not its separate x- and y-components. What I mean is you have to add a vector pointing in the right direction.

As for the blitting stuff, sorry, I really have no clue.
--------------Trans2D - 2D library for C# / Managed DirectX
Ah, I see what you're saying.
Thanks for your help. (Rating++)
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire
Quote:Original post by _Flecko
"Artifacts" just means little graphical problems, like if an image was slightly distorted or something. In particular, I was referring to small areas of my ellipses that don't get drawn. It's clear why this happens: the lines are essentially rotated rectangles, so their corners don't meet up nicely.


Actually the term artifact refers to some graphic element that stays visible from the last frame, when it should not. This occurs for example when the whole viewport isn't redrawn properly so that parts of past geometry still shows. Artifact can be interpreted as an object of past ages that still exist, thus the use of the term in modern graphics. The time from one frame to another is a relatively long time computationally, so one might say that the last frame is a past age for a piece of graphical software. [smile]
Hack my projects! Oh Yeah! Use an SVN client to check them out.BlockStacker
Geeeuuuuw.
Havin' some trouble with my elliptical shapes, because when I render an ellipse or circle [which slows it down pretty good], there is a little empty spot at around 0 radians on the shape, and it's something I can't fix. I'm using the same code as I posted above.

EDIT: Well, I fixed it. Ends up it was dividing out the last vertex when calculating "astep", so I changed it to: "float astep=(pi*2)/(points-1)" (with some error handling of course).

[Edited by - deadimp on June 14, 2005 9:26:42 PM]
Projects:> Thacmus - CMS (PHP 5, MySQL)Paused:> dgi> MegaMan X Crossfire

This topic is closed to new replies.

Advertisement