Jump to content
  • Advertisement
Sign in to follow this  
appdeveloper

C# with DirectX, viewport problem

This topic is 3448 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm developing a game with Visual Studio 2005, using C# and managed DirectX9. My problem is that, in the application, i need several viewports (for now, i have just two), and one of then is not working. The viewport that is working uses TransformedTextured vertexes, but the one that is not working uses PositionedTextured vertexes, once that i need to transform everything in this viewport. I'm after this bug for several weeks. One of the thing i thought that could be the problem is the World of the Microsoft.DirectX.Direct3D.Device.Transform.World. I thought that the current world could be other than the world 0, but i tryed all the others, and they didn't work either. Can you help me, please? Here is part of the code (i've selected what i think its important. hope everything realy important goes here): public delegate void KeyFunction(Microsoft.DirectX.DirectInput.Key k); KeyFunction press; KeyFunction release; const int divs=7; const int perfilSuperior = 7; const int pontosPerfilSuperior = (perfilSuperior-1) * divs; static string gametitle = "GestCeph - Ajuste dos pontos e linhas"; static int screenwidth = 800; //800 static int screenheight = 600; //600 static bool windowed =true; static bool graphicslost = false; static Timer gametimer = null; static bool paused = false; float m_bound_image_height = 0; float m_bound_image_width = 0; float pos_left=0; float pos_top=0; int the_Z=0; private frmTools m_Tools; Direct3D.Device graphics = null; Direct3D.Viewport m_Viewport; Direct3D.Viewport m_Viewport_amplificado; DirectSound.Device sound = null; DirectInput.Device keyboard = null; DirectInput.Device mouse = null; DirectInput.Device gameinput = null; Direct3D.Mesh mesh = null; Direct3D.Material mtrl; private String m_Connection; comunication clsGestCeph; Imagem m_imagem; bool m_tenho_imagem = false; bool m_desenha_perfil_superior = false; bool m_hold_point=false; //true se o mouse estiver a "segurar" um ponto bool bool_tmp; float Medicao_Actual; float Medicao_Real = 100; //float zPos = 10; int contour_color = Color.Red.ToArgb(); //Color.BlueViolet.ToArgb(); int count_pontos = 0; int m_camera_Z_pos = 0; Int32 px, py, pz; String m_cur_img; String m_str_selected=""; Point defPnt; Point ptnAjuda; PointF temp_pointf; Vector3 m_rato; //Vector3 m_camera_pos_viewport_amplificado; //Vector3 m_camera_up_vector_viewport_amplificado; Microsoft.DirectX.DirectInput.Key[] lastpressed = new Microsoft.DirectX.DirectInput.Key[0]; Hashtable m_pontos_coordenadas; Hashtable m_pontos_nome; Hashtable m_pontos_abreviatura; Hashtable m_pontos_bezier_left; Hashtable m_pontos_bezier_right; // -------------------------------------------------------------------- // Resources // -------------------------------------------------------------------- Font windowsfont = null; Direct3D.Font dxfont = null; // -------------------------------------------------------------------- // Geometry // -------------------------------------------------------------------- / Direct3D.CustomVertex.TransformedTextured[] vertexes_mini_ampliado = null; //The one that works_________________ Direct3D.CustomVertex.PositionColored[] vertexColored = null; Direct3D.CustomVertex.PositionColored[] lineColored = null; Direct3D.CustomVertex.PositionTextured[] vertexes = null; //The one that doesnt work_________________ Direct3D.CustomVertex.PositionTextured[] vertexes_rect_points = null; Direct3D.Texture texture = null; Direct3D.Texture point_texture = null; Direct3D.Texture mini_texture = null; // Form public frmImagem() { m_Viewport = new Direct3D.Viewport(); m_Viewport.Height = screenheight; m_Viewport.Width = screenwidth - 150; m_Viewport.X = 0; m_Viewport.Y = 0; m_Viewport.MaxZ = 0; m_Viewport.MinZ = 10; m_Viewport_amplificado = new Direct3D.Viewport(); m_Viewport_amplificado.Height = 200; m_Viewport_amplificado.Width = 150; m_Viewport_amplificado.X = screenwidth - 150; m_Viewport_amplificado.Y = 401; m_Viewport_amplificado.MaxZ = 0; m_Viewport_amplificado.MinZ = 10; Int32 lRet; this.Left = 0; this.Top = 0; lRet = Win32.SetCursorPos(0, 0); defPnt = new Point(); ptnAjuda=this.PointToScreen(new Point(1,1)); //if novo m_pontos_coordenadas=new Hashtable(); m_pontos_nome = new Hashtable(); m_pontos_abreviatura = new Hashtable(); m_pontos_bezier_left = new Hashtable(); m_pontos_bezier_right = new Hashtable(); m_imagem = new Imagem(); clsGestCeph=new comunication(); frmImagem m_form; m_form = this; readXML(); m_Tools = new frmTools(ref m_form); m_Tools.Show(this); m_Tools.TopMost = true; m_imagem.clicked_change_image += new ClickQuerNovaImagem(this.onChanging_Imagem2); ClientSize = new System.Drawing.Size(screenwidth, screenheight); Text = gametitle; gametimer = new Timer(); } // changes the image in every viewport public void onChanging_Imagem(object source, EventArgs e,String the_image) { m_cur_img = the_image; m_tenho_imagem = true; InitializeGeometry(); this.Show(); } public void InitializeGraphics() { // set up the parameters Direct3D.PresentParameters p = new Direct3D.PresentParameters(); p.SwapEffect = Direct3D.SwapEffect.Discard; if (windowed == true) { p.Windowed = true; } else { // get the current display mode: Direct3D.Format current = Direct3D.Manager.Adapters[0].CurrentDisplayMode.Format; // set up a fullscreen display device p.Windowed = false; // fullscreen p.BackBufferFormat = Direct3D.Format.R5G6B5; //current; // use current format p.BackBufferWidth = screenwidth; p.BackBufferHeight = screenheight; } p.EnableAutoDepthStencil = true; p.AutoDepthStencilFormat = Direct3D.DepthFormat.D16; // create a new device: graphics = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, Direct3D.CreateFlags.SoftwareVertexProcessing, p); // Setup the event handlers for the device graphics.DeviceLost += new EventHandler(this.InvalidateDeviceObjects); graphics.DeviceReset += new EventHandler(this.RestoreDeviceObjects); graphics.Disposing += new EventHandler(this.DeleteDeviceObjects); graphics.DeviceResizing += new CancelEventHandler(this.EnvironmentResizing); m_imagem.changed_Image += new ClickImagemAlterada(this.onChanging_Imagem); graphics.Transform.View = Matrix.OrthoOffCenterLH(0, this.Width, this.Height, 0, 10, -10); // set up various drawing options graphics.RenderState.CullMode = Direct3D.Cull.None; graphics.RenderState.AlphaBlendEnable = true; graphics.RenderState.AlphaBlendOperation = Direct3D.BlendOperation.Add; graphics.RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha; graphics.RenderState.SourceBlend = Direct3D.Blend.SourceAlpha; mesh = Direct3D.Mesh.Teapot(graphics); mtrl = new Direct3D.Material(); mtrl.Diffuse = Color.White; graphics.Material = mtrl; } //Creates vertexes public void InitializeGeometry() { vertexes_mini_ampliado = new Direct3D.CustomVertex.TransformedTextured[4]; vertexes = new Direct3D.CustomVertex.PositionTextured [4]; vertexColored = new Direct3D.CustomVertex.PositionColored[m_pontos_coordenadas.Count]; vertexes_rect_points = new Direct3D.CustomVertex.PositionTextured[4]; Vector3 v; PointF tmp_point; int internal_counter; int contador=1; foreach (Int32 key in m_pontos_coordenadas.Keys) { tmp_point = (PointF)m_pontos_coordenadas[key]; internal_counter = contador - 1; v = new Vector3(tmp_point.X, tmp_point.Y, 0); vertexColored[internal_counter].SetPosition(v); vertexColored[internal_counter].Color = Color.Red.ToArgb(); contador++; } vertexes[0].X = m_Viewport.X; vertexes[0].Y = m_Viewport.Y; vertexes[0].Z = 0.0f; vertexes[0].Tu = 0.0f; vertexes[0].Tv = 0.0f; vertexes[1].X =(float)m_imagem.get_ImagemWidth(); m_bound_image_width = vertexes[1].X; vertexes[1].Y = m_Viewport.Y; vertexes[1].Z = 0.0f; vertexes[1].Tu = 1.0f; vertexes[1].Tv = 0.0f; vertexes[2].X = m_Viewport.X; vertexes[2].Y = (float)m_imagem.get_ImagemHeight(); m_bound_image_height = vertexes[2].Y; vertexes[2].Z = 0.0f; vertexes[2].Tu = 0.0f; vertexes[2].Tv = 1.0f; vertexes[3].X = (float)m_imagem.get_ImagemWidth(); vertexes[3].Y = (float)m_imagem.get_ImagemHeight(); vertexes[3].Z = 0.0f; vertexes[3].Tu = 1.0f; vertexes[3].Tv = 1.0f; vertexes_mini_ampliado[0].X = m_Viewport_amplificado.X; vertexes_mini_ampliado[0].Y = m_Viewport_amplificado.Y; vertexes_mini_ampliado[0].Z = 0; vertexes_mini_ampliado[0].Tu = 0.0f; vertexes_mini_ampliado[0].Tv = 0.0f; vertexes_mini_ampliado[1].X =m_Viewport_amplificado.X+ m_Viewport_amplificado.Width; //(float)m_imagem.get_ImagemWidth(); vertexes_mini_ampliado[1].Y = m_Viewport_amplificado.Y; vertexes_mini_ampliado[1].Z = 0; vertexes_mini_ampliado[1].Tu = 1.0f; vertexes_mini_ampliado[1].Tv = 0.0f; vertexes_mini_ampliado[2].X = m_Viewport_amplificado.X; vertexes_mini_ampliado[2].Y =m_Viewport_amplificado.Y+ (m_Viewport_amplificado.Height-1); //(float)m_imagem.get_ImagemHeight(); vertexes_mini_ampliado[2].Z = 0; vertexes_mini_ampliado[2].Tu = 0.0f; vertexes_mini_ampliado[2].Tv = 1.0f; vertexes_mini_ampliado[3].X =m_Viewport_amplificado.X + m_Viewport_amplificado.Width; // (float)m_imagem.get_ImagemWidth(); vertexes_mini_ampliado[3].Y = m_Viewport_amplificado.Y + (m_Viewport_amplificado.Height - 1); // (float)m_imagem.get_ImagemHeight(); vertexes_mini_ampliado[3].Z = 0; vertexes_mini_ampliado[3].Tu = 1.0f; vertexes_mini_ampliado[3].Tv = 1.0f; //---------------------------------------------------------------- if (m_tenho_imagem) { texture = Direct3D.TextureLoader.FromFile( graphics, m_cur_img, 0, 0, 0, 0, Direct3D.Format.Unknown, Direct3D.Pool.Managed, Direct3D.Filter.Linear, Direct3D.Filter.Linear, 0); } else { texture = Direct3D.TextureLoader.FromFile( graphics, "texture.jpg", 0, 0, 0, 0, Direct3D.Format.Unknown, Direct3D.Pool.Managed, Direct3D.Filter.Linear, Direct3D.Filter.Linear, 0); } } // -------------------------------------------------------------------- // Render the current game screen // -------------------------------------------------------------------- protected virtual void Render() { if (graphics != null) { // check to see if the device has been lost. If so, try to get // it back. if (graphicslost) { try { graphics.TestCooperativeLevel(); } catch (Direct3D.DeviceLostException) { // device cannot be reaquired yet, just return return; } catch (Direct3D.DeviceNotResetException) { // device has not been reset, but it can be reaquired now graphics.Reset(graphics.PresentationParameters); } graphicslost = false; } try { graphics.Viewport = m_Viewport; graphics.Clear(Direct3D.ClearFlags.Target | Direct3D.ClearFlags.ZBuffer, Color.Black, 1, 0); graphics.BeginScene(); graphics.SetTexture(0, texture); graphics.VertexFormat = Direct3D.CustomVertex.PositionTextured.Format; if (m_tenho_imagem) { graphics.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleList, 2, vertexes); } graphics.EndScene(); graphics.Present(); //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //--------------------- Viewport Amplificado --------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- graphics.Viewport = m_Viewport_amplificado; graphics.Clear(Direct3D.ClearFlags.Target | Direct3D.ClearFlags.ZBuffer, Color.Black, 1, 0); graphics.BeginScene(); graphics.SetTexture(0,texture); graphics.VertexFormat = Direct3D.CustomVertex.TransformedTextured.Format; if (m_tenho_imagem) { graphics.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, vertexes_mini_ampliado); //graphics.Viewport = m_Viewport; } graphics.EndScene(); graphics.Present(); } // device has been lost, and it cannot be re-initialized yet catch (Direct3D.DeviceLostException) { graphicslost = true; } } } // -------------------------------------------------------------------- // Run the game // -------------------------------------------------------------------- public void Run() { // reset the game timer gametimer.Reset(); // loop while form is valid while (this.Created) { // process one frame of the game SetupCamera(); ProcessFrame(); SetupLights(); // render the current scene Render(); // handle all events Application.DoEvents(); } } My thanks in advanced

Share this post


Link to post
Share on other sites
Advertisement
Ok, i've tested to clear the viewport with the color blue.
A rectangle is being drawn, but the texture is not being set. So the problem seems to be the texture. So, in the
graphics.SetTexture(0, texture);

what is the first parameter? stage? what does this means?
I've changed this value, but still, doesn't work

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!