#22 Members - Reputation: 112
Posted 11 January 2012 - 11:44 AM
I think there could be some 'fighting' between the values when they are too near together. In OpenGL I can do this. Ideas?
Edit: I am trying to use this
Matrix.OrthoLH(Screenwidth, Screenheight, zNear, zFar);This works, but if I am using screenpositions now for drawing, the textures are shifted to the mid of the screen. Basically, position 0,0 is the center of the screen, but I want it to be at the top left.
#25 Members - Reputation: 112
Posted 13 January 2012 - 07:41 AM
private void RResize()
{
h = control.Height;
w = control.Width;
y = 0;
x = 0;
if ((float)w / (float)h > CSettings.GetRenderAspect())
{
w = (int)Math.Round((float)h * CSettings.GetRenderAspect());
x = (control.Width - w) / 2;
}
else
{
h = (int)Math.Round((float)w / CSettings.GetRenderAspect());
y = (control.Height - h) / 2;
}
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, CSettings.iRenderW, CSettings.iRenderH, 0, (double)CSettings.zNear, (double)CSettings.zFar);
GL.Viewport(x, y, w, h);
}
For DirectX i was trying with:
private void RResize()
{
h = this.Height;
w = this.Width;
y = 0;
x = 0;
if ((float)w / (float)h > CSettings.GetRenderAspect())
{
w = (int)Math.Round((float)h * CSettings.GetRenderAspect());
x = (this.Width - w) / 2;
}
else
{
h = (int)Math.Round((float)w / CSettings.GetRenderAspect());
y = (this.Height - h) / 2;
}
if(_Run)
{
m_Device.Viewport= new Viewport(x, y, w, h);
}
}
But I am getting
Direct3D9: (ERROR) :Viewport outside the render target surface
Another one is when I open up the task manager or a UAC window appears, my device is lost. I think I have to call Device.Reset(). After I disposed all objects, i need a way to recreate the textures which are lost in this process. I need help doing this
Edit2: I am still stuck at resizing my window with the correct aspect ratio. If I set the viewport like this it will go out of my window, it is shifted the right way though but the width and height is too big
#26 Members - Reputation: 112
Posted 18 January 2012 - 12:47 PM
http://pastebin.com/QNHABBm5
Edit: I came up with an idea: Could I write all Vertices into a list, which is only rendered once per frame(in my MainLoop) and is discarded after? Is this the way not to lock the VertexBuffer several times a frame? Which size is common for a vertexbuffer? Right now I am using this size
4 * Marshal.SizeOf(typeof(TexturedColoredVertex), which is rather small i think. I heard I can draw several vertices a time, so i would be using a factor of my current size?
#27 Members - Reputation: 112
Posted 21 January 2012 - 04:39 PM
Right now I am resizing my viewport but it seems as if the width and height parameters are ignored, the frame will shift by my x and y coordinates but it wont use the width and height i specified so that it is running out of my window.
Do I have to set the backbuffer width and height? Do I have to change something at my orthogonal projection or my translation matrix?
#28 Members - Reputation: 112
Posted 25 January 2012 - 08:09 AM
using (MemoryStream stream = new MemoryStream())
{
bmp2.Save(stream, ImageFormat.Png);
stream.Position = 0;
Texture t = Texture.FromStream(_Device, stream, 0, w, h, 0, Usage.None, Format.A8R8G8B8, Pool.Managed, Filter.Default, Filter.Default, 0);
_D3DTextures.Add(t);
}
Unfortunetely there is no Method for Texture.FromBitmap in SlimDx. Can someone help?
#30 Crossbones+ - Reputation: 5172
Posted 28 January 2012 - 07:17 AM
Just because no one else mentioned this, OpenGL and Direct3D 10 assume center-points for pixels.OpenGL interprets screen-space positions as the center of the pixel
DirectX interprets screen-space positions as the top-left corner of the pixel
(Or is it the other way round?)
Direct3D 9, Direct3D 11, and GDI use pixel corners.
If you are only setting the viewport on a resize, you need to also update your orthogonal matrix.Right now I am resizing my viewport but it seems as if the width and height parameters are ignored, the frame will shift by my x and y coordinates but it wont use the width and height i specified so that it is running out of my window.
Do I have to set the backbuffer width and height? Do I have to change something at my orthogonal projection or my translation matrix?
I don’t see the problem.I got a problem that the textures are clipped when they reach the edges of the viewport. I am creating my VertexBuffer with the DoNotClip Flag and I am setting the RenderState.Clipping to false. Am I missing another flag?
The viewport should be the size of the screen. If anything goes out of the viewport it would be outside of the window and you would never know if it was clipped or not.
I see no clipping in your screen shot.
L. Spiro
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums
#31 Members - Reputation: 112
Posted 28 January 2012 - 07:29 AM
By the way this is how I am roting a quad:
if (rect.Rotation != 0)
{
rect.Rotation = rect.Rotation * (float)Math.PI / 180;
float centerX = (rx1 + rx2) / 2f;
float centerY = -(ry1 + ry2) / 2f;
Matrix originTranslation = _Device.GetTransform(TransformState.World);
Matrix translationA = Matrix.Translation(-centerX, -centerY, 0);
Matrix rotation = Matrix.RotationZ(-rect.Rotation);
Matrix translationB = Matrix.Translation(centerX, centerY, 0);
Matrix result = translationA * rotation * translationB * originTranslation;
_Device.SetTransform(TransformState.World, result);
}
This is the full source code: http://pastebin.com/yDDuiZV1
I am happy for every improvement ideas =)
I think its the Orthographic Projection I'm using. If a Point of a Vertex would go over my Projection it wont show up I believe, but in OpenGL it does its really confusing and im stuck here






