Problem rendering with vertex buffer
Hi, I'm trying to draw a textured square to the screen using ManagedDX 1.1. Unfortunately, the DrawPrimitives call is giving me an exception, but all the error message says is "Error in the application" which is not very helpful. I really have no idea what is wrong, because this was working before and it's stopped working when I was reorganizing the code in my classes. I've pasted the two functions which I think are relevant, if anyone has any suggestions I would greatly appreciate it.
(also, the code below seems like a terrible way to update the data in the vertex buffer, if anyone could point me to a "more correct" way of doing things that would be good too :)
public
{
UpdateVertexBuffer(dest_pt.X, dest_pt.Y);
mDevice.RenderState.AlphaBlendEnable =true;
mDevice.RenderState.SourceBlend =Blend.SourceAlpha;
mDevice.RenderState.DestinationBlend =Blend.InvSourceAlpha;
mDevice.SetTexture(0, mTexture);
mDevice.TextureState[0].AlphaArgument1 =TextureArgument.TextureColor;
mDevice.TextureState[0].AlphaArgument2 =TextureArgument.Diffuse;
mDevice.TextureState[0].AlphaOperation =TextureOperation.Modulate;
mDevice.SetStreamSource(0, mVertices,0);
mDevice.DrawPrimitives(PrimitiveType.TriangleStrip,0,2);
}
protected
void UpdateVertexBuffer(int dest_x,int dest_y){
if (mVertices ==null){
mVertices = CreateVertexBuffer(
0,0);}
CustomVertex.TransformedColoredTextured[] verts =(
CustomVertex.TransformedColoredTextured[]) mVertices.Lock(0,0);// find centerPoint centerpt =Origin.Calc(mOwner.DisplayAlignment, mOwner.DisplaySize);Point rotation =Origin.Calc(mOwner.RotationCenter, mOwner.DisplaySize);rotation.X += dest_x;
rotation.Y += dest_y;
Point[] corners =newPoint[4]{
newPoint(dest_x, dest_y),newPoint(dest_x + mOwner.DisplayWidth, dest_y),newPoint(dest_x, dest_y + mOwner.DisplayHeight),newPoint(dest_x + mOwner.DisplayWidth, dest_y + mOwner.DisplayHeight)};
PointF[] uv =newPointF[4]{
newPointF(0,0),newPointF(1,0),newPointF(0,1),newPointF(1,1),};
if (mOwner.DisplayWidth <0){
// swap pointsfor (int i =0; i <4; i +=2){
Point t = cornerscorners
= corners[i +
corners[i +
1] = t;PointF uvt = uvuv
= uv[i +
uv[i +
1] = uvt;}
for (int i =0; i <4; i++)corners
.X -= mOwner.DisplayWidth;
}
if (mOwner.DisplayHeight <0){
// swap pointsfor (int i =0; i <2; i +=1){
Point t = cornerscorners
= corners[i +
corners[i +
2] = t;PointF uvt = uvuv
= uv[i +
uv[i +
2] = uvt;}
for (int i =0; i <4; i++)corners
.Y -= mOwner.DisplayHeight;
}
// do rotation and translationif (mOwner.RotationAngle !=0){
for (int i =0; i <4; i++){
RotatePointInPlace(
ref cornersTranslatePointInPlace(
ref corners}
}
else{
for (int i =0; i <4; i++){
TranslatePointInPlace(
ref corners}
}
for (int i =0; i <4; i++){
verts
=
(
float)corners}
mVertices.Unlock();
}

