Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Rendering on top of textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 MatsK   Members   -  Reputation: 155

Like
0Likes
Like

Posted 25 December 2011 - 09:02 AM

Right, I made a topic about this before, but never seemed to get any answers that were helping my situation.
I've been experimenting in a tool I made, and eventually found out that one of the reasons rendering wasn't working correctly in my client was because when done between a call to SpriteBatch.Begin() and SpriteBatch.End(), meshes end up being transparent.
I fixed this in the client, but meshes were still rendered transparently!
So after messing about some more in the tool I made, it would appear as though having SpriteBatch.Being() and SpriteBatch.End() in the drawingloop at all seems to fuck up rendering... does anyone have any ideas?
And going to XNA 4.0 isn't an option, because XNA 4.0 doesn't support loading BMPs from memory.

Correctly formatted source listing

using 
System;
using System.Collections.Generic;
using 
System.ComponentModel;
using System.Data;
using System.Drawing;
using 
System.Text;
using System.Windows.Forms;
using System.IO;
using XNA = 
Microsoft.Xna.Framework;
using Microsoft.Xna.Framework;
using 
Microsoft.Xna.Framework.Graphics;
using Microsoft.Win32;


namespace XNAWinForms
{
    /// 
<summary>
    /// Windows form that inherits from 
XNAWinForms and adds the rendering of a simple rotating 
triangle
    /// 
    /// Author: Iñaki 
Ayucar ([url="http://graphicdna.blogspot.com"]http://graphicdna.blogspot.com[/url])
    
/// Date: 14/11/2007
    /// 
    /// This 
software is distributed "for free" for any non-commercial usage. The software is 
provided “as-is.” 
    /// You bear the risk of using it. The 
contributors give no express warranties, guarantees or 
conditions.
    /// </summary>
    
public partial class Form1 : XNAWinForm
    
{
        private Outfit 
m_CurrentOutfit;
        private 
Appearance m_CurrentAppearance;


        private Skeleton m_Skeleton; 
//Defaults to 'adult.skel' unless we are dealing with a dog or 
cat.
        private Mesh 
m_CurrentMesh;
        private Texture2D 
m_Tex;
        bool m_LoadComplete = 
false;


        private float mRotation = 
0f;
        private Matrix mViewMat, 
mWorldMat, mProjectionMat;
        private 
BasicEffect mSimpleEffect;


        private 
VertexPositionNormalTexture[] m_NormVerticies;


        private SpriteBatch 
m_SBatch;
        private Texture2D 
m_BackgroundTex;


        /// 
<summary>
        /// 

        /// 
</summary>
        public 
Form1()
        
{
            
InitializeComponent();


            
this.DeviceResetting += new 
XNAWinForm.EmptyEventHandler(mWinForm_DeviceResetting);
            
this.DeviceReset += new 
XNAWinForm.GraphicsDeviceDelegate(mWinForm_DeviceReset);
            
this.OnFrameRender += new 
XNAWinForm.GraphicsDeviceDelegate(mWinForm_OnFrameRender);
            
this.OnFrameMove += new GraphicsDeviceDelegate(Form1_OnFrameMove);


            mViewMat = 
mWorldMat = mProjectionMat = Matrix.Identity;


            //Check 
for the existence of TSO on the user's machine, and get the correct 
installation-path.
            
RegistryKey softwareKey = 
Registry.LocalMachine.OpenSubKey("SOFTWARE");
            
if (Array.Exists(softwareKey.GetSubKeyNames(), delegate(string s) { return 
s.CompareTo("Maxis") == 0; 
}))
            
{
                
RegistryKey maxisKey = 
softwareKey.OpenSubKey("Maxis");
                
if (Array.Exists(maxisKey.GetSubKeyNames(), delegate(string s) { return 
s.CompareTo("The Sims Online") == 0; 
}))
                
{
                    
RegistryKey tsoKey = maxisKey.OpenSubKey("The Sims 
Online");
                    
string installDir = 
(string)tsoKey.GetValue("InstallDir");
                    
installDir += "[url="file://\\TSOClient\\"]\\TSOClient\\[/url]";
                    
GlobalSettings.Default.StartupPath = 
installDir;
                
}
                
else
                
{
                    
MessageBox.Show("Error TSO was not found on your 
system.");
                    
Application.Exit();


                    
//TODO: Let user select path 
manually...
                
}
            
}
            
else
            
{
                
MessageBox.Show("Error: No Maxis products were found on your 
system.");
                
Application.Exit();
            
}


            foreach 
(KeyValuePair<ulong, string> Pair in 
ContentManager.Resources)
            
{
                
if 
(Pair.Value.Contains(".po"))
                    
LstHeads.Items.Add(Pair.Value);
            
}


            m_Skeleton 
= new Skeleton(ContentManager.GetResourceFromLongID(0x100000005));


            
LstHeads.SelectedIndexChanged += new 
EventHandler(LstHeads_SelectedIndexChanged);
        
}


        /// 
<summary>
        /// User clicked 
on an item in the list containing available heads and 
bodies.
        /// 
</summary>
        private void 
LstHeads_SelectedIndexChanged(object sender, EventArgs 
e)
        
{
            
foreach(KeyValuePair<ulong, string> Pair in 

ContentManager.Resources)
            
{
                
if ((string)LstHeads.SelectedItem == 
Pair.Value)
                
{
                    
PurchasableObject PO = new 
PurchasableObject(ContentManager.GetResourceFromLongID(Pair.Key));


                    
m_CurrentOutfit = new 
Outfit(ContentManager.GetResourceFromLongID(PO.OutfitID));
                    
m_CurrentAppearance = new 
Appearance(
                        
ContentManager.GetResourceFromLongID(m_CurrentOutfit.LightAppearanceID));


                    
List<Binding> Bindings = new List<Binding>();


                    
foreach (ulong BindingID in 
m_CurrentAppearance.BindingIDs)
                        
Bindings.Add(new Binding(ContentManager.GetResourceFromLongID(BindingID)));


                    
m_Tex = Texture2D.FromFile(this.Device, new 
MemoryStream(
                        
ContentManager.GetResourceFromLongID(Bindings[0].TextureAssetID)));


                    
m_CurrentMesh = new 
Mesh(ContentManager.GetResourceFromLongID(Bindings[0].MeshAssetID));
                    
LoadMesh(m_CurrentMesh);


                    
//The file selected was most likely a body-mesh, so apply the adult skeleton to 
it.
                    
if 
(Pair.Value.Contains("bodies"))
                    
{
                        
foreach (Bone Bne in 
m_Skeleton.Bones)
                        
{
                            
VertexPositionNormalTexture[] TransformedVerticies = 

                                
new VertexPositionNormalTexture[m_CurrentMesh.VertexCount];


                            
foreach (BoneBinding Bnd in 
m_CurrentMesh.BoneBindings)
                            
{
                                
if (Bne.ID == 
Bnd.BoneIndex)
                                
{
                                    
int Counter = 0;


                                    
if (Bnd.FirstVertex != 
-1)
                                    
{
                                        
for (int i = Bnd.FirstVertex; i < Bnd.VertexCount; 
i++)
                                        
{
                                            
Vector3 TransformedVector = 
Vector3.Transform(
                                                
m_NormVerticies[i].Position, new 
Quaternion(Bne.Quaternions[0],
                                                    
Bne.Quaternions[1], Bne.Quaternions[2], 
Bne.Quaternions[3]));
                                            
TransformedVerticies[Counter].Position = TransformedVector;


                                            
//I think these should be transformed as 
well.
                                            
Vector3 TransformedNormal = 
Vector3.Transform(
                                                
m_NormVerticies[i].Normal, new 
Quaternion(Bne.Quaternions[0],
                                                    
Bne.Quaternions[1], Bne.Quaternions[2], 
Bne.Quaternions[3]));
                                            
TransformedNormal.Normalize();
                                            
TransformedVerticies[Counter].Normal = TransformedNormal;


                                            
//But you never need to blend the 2d texture coordinates, they are always 
the
                                            
//same. i.e. some mesh vertices straddle two bones, so they are the weighted 

                                            
//average of a the vertex attached to one bone, and the vertex attached to the 

                                            
//other bone. But the texture coordinate of that blended vertex always 

                                            
//comes from the original, and is not blended. 

                                            
/*Vector2 TransformedUV = 
Vector2.Transform(m_NormVerticies[i].TextureCoordinate,
                                                
new Quaternion(Bne.Quaternions[0], Bne.Quaternions[1], 
Bne.Quaternions[2],
                                                    
Bne.Quaternions[3]));
                                            
TransformedVerticies[Counter].TextureCoordinate = TransformedUV;*/


                                            
if (m_CurrentMesh.BlendCount > 
0)
                                            
{
                                                
for (int j = Bnd.FirstBlendedVert; j < Bnd.BlendedVertexCount; 
j++)
                                                
{
                                                    
m_CurrentMesh.Blend(TransformedVerticies[m_CurrentMesh.Blends[j].OtherVertexIndex].Position,
                                                        
TransformedVerticies[j + 
m_CurrentMesh.TexVertexCount].Position,
                                                        ref TransformedVerticies[m_CurrentMesh.Blends[j].OtherVertexIndex], Bne.Quaternions[3]);
                                                
}
                                            
}


                                            
m_NormVerticies[i] = TransformedVerticies[Counter];


                                            
Counter++;
                                        
}
                                    
}
                                
}
                            
}
                        
}
                    
}


                    
m_LoadComplete = 
true;
                
}
            
}
        }


        /// 
<summary>
        /// 

        /// 
</summary>
        /// <param 
name="pDevice"></param>
        
private void Form1_OnFrameMove(Microsoft.Xna.Framework.Graphics.GraphicsDevice 
pDevice)
        
{
            
mRotation += 
0.05f;
            
this.mWorldMat = 
Matrix.CreateRotationY(mRotation);
        
}
        /// 
<summary>
        /// 

        /// 
</summary>
        /// <param 
name="pDevice"></param>
        
private void mWinForm_OnFrameRender(GraphicsDevice 
pDevice)
        
{
            
m_SBatch.Begin();


            
m_SBatch.Draw(m_BackgroundTex, new Microsoft.Xna.Framework.Rectangle(0, 0, 
m_BackgroundTex.Width,
                
m_BackgroundTex.Height), Microsoft.Xna.Framework.Graphics.Color.White);


            
m_SBatch.End();


            
Device.RenderState.DepthBufferEnable = 
true;
            
Device.RenderState.DepthBufferWriteEnable = 
true;
            
Device.RenderState.AlphaBlendEnable = false;


            // 
Configure 
effect
            
mSimpleEffect.World = 
this.mWorldMat;
            
mSimpleEffect.View = 
this.mViewMat;
            
mSimpleEffect.Projection = this.mProjectionMat;


            if (m_Tex 
!= null)
            
{
                
mSimpleEffect.Texture = 
m_Tex;
                
mSimpleEffect.TextureEnabled = true;


                
mSimpleEffect.EnableDefaultLighting();
            
}


            
mSimpleEffect.CommitChanges();


            // 
Draw
            
mSimpleEffect.Begin();
            
mSimpleEffect.Techniques[0].Passes[0].Begin();


            if 
(m_NormVerticies != 
null)
            
{
                
if 
(m_LoadComplete)
                
{
                    
foreach (Face Fce in 
m_CurrentMesh.Faces)
                    
{
                        
VertexPositionNormalTexture[] Vertex = new 
VertexPositionNormalTexture[3];
                        
Vertex[0] = 
m_NormVerticies[Fce.AVertexIndex];
                        
Vertex[1] = 
m_NormVerticies[Fce.BVertexIndex];
                        
Vertex[2] = m_NormVerticies[Fce.CVertexIndex];


                        
Vertex[0].TextureCoordinate = 
m_NormVerticies[Fce.AVertexIndex].TextureCoordinate;
                        
Vertex[1].TextureCoordinate = 
m_NormVerticies[Fce.BVertexIndex].TextureCoordinate;
                        
Vertex[2].TextureCoordinate = 
m_NormVerticies[Fce.CVertexIndex].TextureCoordinate;


                        
pDevice.DrawUserPrimitives<VertexPositionNormalTexture>(PrimitiveType.TriangleList,
                            
Vertex, 0, 
1);
                    
}
                
}
            }


            
mSimpleEffect.Techniques[0].Passes[0].End();
            
mSimpleEffect.End();
        }


        private DepthStencilBuffer 
CreateDepthStencil(RenderTarget2D 
target)
        
{
            return 
new DepthStencilBuffer(target.GraphicsDevice, 
target.Width,
                
target.Height, 
target.GraphicsDevice.DepthStencilBuffer.Format,
                
target.MultiSampleType, 
target.MultiSampleQuality);
        }


        /// 
<summary>
        /// 

        /// 
</summary>
        /// <param 
name="pDevice"></param>
        
private void mWinForm_DeviceReset(GraphicsDevice 
pDevice)
        
{
            // 
Re-Create 
effect
            
mSimpleEffect = new BasicEffect(pDevice, null);


            // 
Configure 
device
            
pDevice.VertexDeclaration = new VertexDeclaration(pDevice, 
VertexPositionNormalTexture.VertexElements);
            
//Should this be set to another 
setting?
            
pDevice.RenderState.CullMode = CullMode.None;


            // Create 
camera and projection 
matrix
            
mWorldMat = 
Matrix.Identity;
            
mViewMat = Matrix.CreateLookAt(Vector3.Right * 5,Vector3.Zero, 
Vector3.Forward);
            
mProjectionMat = Matrix.CreatePerspectiveFieldOfView(MathHelper.Pi / 
4.0f,
                    
(float)pDevice.PresentationParameters.BackBufferWidth / 
(float)pDevice.PresentationParameters.BackBufferHeight,
                    
1.0f, 100.0f);


            m_SBatch = 
new 
SpriteBatch(Device);
            
m_BackgroundTex = Texture2D.FromFile(Device, File.Open("sims-online-1.jpg", 
FileMode.Open));
        
}
        /// 
<summary>
        /// 

        /// 
</summary>
        private void 
mWinForm_DeviceResetting()
        
{
            // 
Dispose 
all
            if 
(mSimpleEffect != 
null)
                
mSimpleEffect.Dispose();
        }


        private void 
openToolStripMenuItem_Click(object sender, EventArgs 
e)
        
{
            
OpenFileDialog OpenFDiag = new 
OpenFileDialog();
            
OpenFDiag.Filter = "Mesh 
file|*.mesh";
            
OpenFDiag.Title = "Select a mesh to open...";


            if 
(OpenFDiag.ShowDialog() == 
DialogResult.OK)
            
{
                
m_CurrentMesh = new 
Mesh(OpenFDiag.FileName);
                
LoadMesh(m_CurrentMesh);


                
string TextureName = OpenFDiag.FileName.Replace("meshes", 
"textures").Replace("mesh", 
"jpg").
                    
Replace("fah", "").Replace("fa", "falgt").Replace("-head-head", "");


                
m_Tex = Texture2D.FromFile(this.Device, 
TextureName);
                
m_LoadComplete = 
true;
            
}
        }


        private void LoadMesh(Mesh 
MeshToLoad)
        
{
            
m_NormVerticies = new VertexPositionNormalTexture[MeshToLoad.VertexCount];


            for (int i 
= 0; i < MeshToLoad.VertexCount; 
i++)
            
{
                
m_NormVerticies[i] = new 
VertexPositionNormalTexture();
                
m_NormVerticies[i].Position.X = MeshToLoad.VertexData[i, 
0];
                
m_NormVerticies[i].Position.Y = MeshToLoad.VertexData[i, 
1];
                
m_NormVerticies[i].Position.Z = MeshToLoad.VertexData[i, 
2];
                
m_NormVerticies[i].Normal.X = MeshToLoad.VertexData[i, 
3];
                
m_NormVerticies[i].Normal.Y = MeshToLoad.VertexData[i, 
4];
                
m_NormVerticies[i].Normal.Z = MeshToLoad.VertexData[i, 5];



                
//Not really sure why this is important, but I think it has something to 
do
                
//with being able to see the 
texture.
                
//m_NormVerticies[i].Normal.Normalize();
            
}


            for (int i 
= 0; i < MeshToLoad.TexVertexCount; 
i++)
            
{
                
m_NormVerticies[i].TextureCoordinate.X = MeshToLoad.TextureVertData[i, 
1];
                
m_NormVerticies[i].TextureCoordinate.Y = MeshToLoad.TextureVertData[i, 
2];
            
}
        }
        private void 
exitToolStripMenuItem_Click(object sender, EventArgs 
e)
        
{
            
Application.Exit();
        
}
    }
}



Sponsor:

#2 Tsus   Members   -  Reputation: 790

Like
1Likes
Like

Posted 25 December 2011 - 10:02 AM

Hi,

So after messing about some more in the tool I made, it would appear as though having SpriteBatch.Being() and SpriteBatch.End() in the drawingloop at all seems to fuck up rendering... does anyone have any ideas?

If the sprite batch messes up your rendering it’s perhaps because spriteBatch.Begin() changes render states. If that’s your problem, you can resolve it by telling the spriteBatch to restore all states at spriteBatch.End(). Have you tried that? You can do it by using the SaveState flag:
spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.BackToFront, SaveStateMode.SaveState);
You could also check in PIX whether all render states are set as you expect.

Acagamics e.V. – IGDA Student Game Development Club (University of Magdeburg, Germany)


#3 MatsK   Members   -  Reputation: 155

Like
0Likes
Like

Posted 25 December 2011 - 12:08 PM

w00t!

That worked, thanks so much! :D

#4 MatsK   Members   -  Reputation: 155

Like
0Likes
Like

Posted 28 December 2011 - 02:02 PM

Ok, so now I've been doing that, but I realize that it messes up the GUI (the GUI doesn't seem to want to redraw itself!!)
I tried not using the SaveStates flag and spawning 3D-rendering in a separate thread, but the rendering ends up exactly the way it was in the main thread.
The funny thing is that the redraw-problem doesn't seem to occur until after I've started 3D-rendering. Until then, the GUI draws and updates fine.

Here's my "Game1.cs" file:

/*The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is the TSO LoginServer.
The Initial Developer of the Original Code is
Mats 'Afr0' Vederhus. All Rights Reserved.
Contributor(s):
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using System.Threading;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using TSOClient;
using TSOClient.LUI;
using TSOClient.Network;
using TSOClient.ThreeD;
using SimsLib.FAR3;
using LogThis;
using NAudio.Wave;
using Un4seen.Bass;
using Microsoft.Win32;
namespace TSOClient
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
	    GraphicsDeviceManager graphics;
	    SpriteBatch spriteBatch;
	    public ScreenManager ScreenMgr;
	    public SceneManager SceneMgr;
	    private Dictionary<int, string> m_TextDict = new Dictionary<int, string>();
	    public Game1()
	    {
		    graphics = new GraphicsDeviceManager(this);
		    Content.RootDirectory = "Content";
		    Log.UseSensibleDefaults();
	    }
	    /// <summary>
	    /// Allows the game to perform any initialization it needs to before starting to run.
	    /// This is where it can query for any required services and load any non-graphic
	    /// related content.  Calling base.Initialize will enumerate through any components
	    /// and initialize them as well.
	    /// </summary>
	    protected override void Initialize()
	    {
		    // TODO: Add your initialization logic here
		    graphics.PreferredBackBufferWidth = 800;
		    graphics.PreferredBackBufferHeight = 600;
		    GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice,
			    VertexPositionNormalTexture.VertexElements);
		    GraphicsDevice.RenderState.CullMode = CullMode.None;
		    BassNet.Registration("afr088@hotmail.com", "2X3163018312422");
		    Bass.BASS_Init(-1, 8000, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero, System.Guid.Empty);
		    this.IsMouseVisible = true;
		    //Might want to reconsider this...
		    this.IsFixedTimeStep = false;
		    graphics.SynchronizeWithVerticalRetrace = false;
		    //InitLoginNotify - 65 bytes
		    //NetworkClient.RegisterLoginPacketID(0x01, 65);
		    NetworkClient.RegisterLoginPacketID(0x01, 2);
		    //LoginFailResponse - 2 bytes
		    NetworkClient.RegisterLoginPacketID(0x02, 2);
		    //LoginSuccessResponse - 33 bytes
		    NetworkClient.RegisterLoginPacketID(0x04, 33);
		    NetworkClient.RegisterLoginPacketID(0x05, 0);
		    //This should ideally be stored in the Windows Registry...
		    RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("SOFTWARE");
		    if (Array.Exists(softwareKey.GetSubKeyNames(), delegate(string s) { return s.CompareTo("Maxis") == 0; }))
		    {
			    RegistryKey maxisKey = softwareKey.OpenSubKey("Maxis");
			    if (Array.Exists(maxisKey.GetSubKeyNames(), delegate(string s) { return s.CompareTo("The Sims Online") == 0; }))
			    {
				    RegistryKey tsoKey = maxisKey.OpenSubKey("The Sims Online");
				    string installDir = (string)tsoKey.GetValue("InstallDir");
				    installDir += "\\TSOClient\\";
				    GlobalSettings.Default.StartupPath = installDir;
			    }
			    else
				    MessageBox.Show("Error TSO was not found on your system.");
		    }
		    else
			    MessageBox.Show("Error: No Maxis products were found on your system.");

		    //GlobalSettings.Default.StartupPath = "C:\\Program Files\\Maxis\\The Sims Online\\TSOClient\\";
		    base.Initialize();
	    }
	    /// <summary>
	    /// LoadContent will be called once per game and is the place to load
	    /// all of your content.
	    /// </summary>
	    protected override void LoadContent()
	    {
		    // Create a new SpriteBatch, which can be used to draw textures.
		    spriteBatch = new SpriteBatch(GraphicsDevice);
		    // TODO: use this.Content to load your game content here
		    int Channel = Bass.BASS_StreamCreateFile("Sounds\\BUTTON.WAV", 0, 0, BASSFlag.BASS_DEFAULT);
		    UISounds.AddSound(new UISound(0x01, Channel));
		    ScreenMgr = new ScreenManager(this, Content.Load<SpriteFont>("ComicSans"),
			    Content.Load<SpriteFont>("ComicSansSmall"));
		    SceneMgr = new SceneManager(this);
		    ThreadPool.QueueUserWorkItem(new WaitCallback(Draw3D));
		    //Make the screenmanager, scenemanager and the startup path globally available to all Lua scripts.
		    LuaInterfaceManager.ExportObject("ScreenManager", ScreenMgr);
		    LuaInterfaceManager.ExportObject("ThreeDManager", SceneMgr);
		    LuaInterfaceManager.ExportObject("StartupPath", GlobalSettings.Default.StartupPath);
		   
		    //Read settings...
		    LuaFunctions.ReadSettings("gamedata\\settings\\settings.lua");
		    LoadStrings();
		    ScreenMgr.TextDict = m_TextDict;
		    ScreenMgr.LoadInitialScreen("gamedata\\luascripts\\login.lua");
		    //ScreenMgr.LoadInitialScreen("gamedata\\luascripts\\loading.lua");
		    //ContentManager.InitLoading(ScreenMgr);
	    }
	    /// <summary>
	    /// UnloadContent will be called once per game and is the place to unload
	    /// all content.
	    /// </summary>
	    protected override void UnloadContent()
	    {
		    // TODO: Unload any non ContentManager content here
	    }
	    private float m_FPS = 0;
	    /// <summary>
	    /// Allows the game to run logic such as updating the world,
	    /// checking for collisions, gathering input, and playing audio.
	    /// </summary>
	    /// <param name="gameTime">Provides a snapshot of timing values.</param>
	    protected override void Update(GameTime gameTime)
	    {
		    m_FPS = (float)(1 / gameTime.ElapsedGameTime.TotalSeconds);
		    // Allows the game to exit
		    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
			    this.Exit();
		    // TODO: Add your update logic here
		    ScreenMgr.Update(gameTime);
		    SceneMgr.Update(gameTime);
		    base.Update(gameTime);
	    }
	    /// <summary>
	    /// This is called when the game should draw itself.
	    /// </summary>
	    /// <param name="gameTime">Provides a snapshot of timing values.</param>
	    protected override void Draw(GameTime gameTime)
	    {
		    base.Draw(gameTime);
		   
		    GraphicsDevice.Clear(new Color(23, 23, 23));
		    //Deferred sorting seems to just work...
		    //NOTE: Using SaveStateMode.SaveState is IMPORTANT to make 3D rendering work properly!
		    spriteBatch.Begin(/*SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.SaveState*/);
		    ScreenMgr.Draw(spriteBatch, m_FPS);
		    spriteBatch.End();
		    //SceneMgr.Draw();
	    }
	    private void Draw3D(object Obj)
	    {
		    while (true)
		    {
			    SceneMgr.Draw();
		    }
	    }
	    /// <summary>
	    /// Loads the correct set of strings based on the current language.
	    /// This method is a bit of a hack, but it works.
	    /// </summary>
	    private void LoadStrings()
	    {
		    string CurrentLang = GlobalSettings.Default.CurrentLang.ToLower();
		    LuaInterfaceManager.RunFileInThread("gamedata\\uitext\\luatext\\" +
			    CurrentLang + "\\" + CurrentLang + ".lua");
		    m_TextDict.Add(1, (string)LuaInterfaceManager.LuaVM["LoginName"]);
		    m_TextDict.Add(2, (string)LuaInterfaceManager.LuaVM["LoginPass"]);
		    m_TextDict.Add(3, (string)LuaInterfaceManager.LuaVM["Login"]);
		    m_TextDict.Add(4, (string)LuaInterfaceManager.LuaVM["Exit"]);
		    m_TextDict.Add(5, (string)LuaInterfaceManager.LuaVM["OverallProgress"]);
		    m_TextDict.Add(6, (string)LuaInterfaceManager.LuaVM["CurrentTask"]);
		    m_TextDict.Add(7, (string)LuaInterfaceManager.LuaVM["InfoPopup1"]);
		    m_TextDict.Add(8, (string)LuaInterfaceManager.LuaVM["PersonSelectionCaption"]);
		    m_TextDict.Add(9, (string)LuaInterfaceManager.LuaVM["TimeStart"]);
		    m_TextDict.Add(10, (string)LuaInterfaceManager.LuaVM["PersonSelectionEditCaption"]);
		    m_TextDict.Add(11, (string)LuaInterfaceManager.LuaVM["CreateASim"]);
		    m_TextDict.Add(12, (string)LuaInterfaceManager.LuaVM["RetireASim"]);
		    //Loading strings
		    m_TextDict.Add(13, (string)LuaInterfaceManager.LuaVM["LoadText1"]);
		    m_TextDict.Add(14, (string)LuaInterfaceManager.LuaVM["LoadText2"]);
		    m_TextDict.Add(15, (string)LuaInterfaceManager.LuaVM["LoadText3"]);
		    m_TextDict.Add(16, (string)LuaInterfaceManager.LuaVM["LoadText4"]);
		    m_TextDict.Add(17, (string)LuaInterfaceManager.LuaVM["LoadText5"]);
		    m_TextDict.Add(18, (string)LuaInterfaceManager.LuaVM["LoadText6"]);
		    m_TextDict.Add(19, (string)LuaInterfaceManager.LuaVM["LoadText7"]);
		    m_TextDict.Add(20, (string)LuaInterfaceManager.LuaVM["LoadText8"]);
		    m_TextDict.Add(21, (string)LuaInterfaceManager.LuaVM["LoadText9"]);
		    m_TextDict.Add(22, (string)LuaInterfaceManager.LuaVM["LoadText10"]);
		    m_TextDict.Add(23, (string)LuaInterfaceManager.LuaVM["LoadText11"]);
	    }
    }
}

Any ideas?

#5 MatsK   Members   -  Reputation: 155

Like
0Likes
Like

Posted 28 December 2011 - 03:40 PM

Nevermind, I did some experiments and found that the problem must have been introduced earlier.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS