• Content count

  • Joined

  • Last visited

Community Reputation

126 Neutral

About kobuscrispi

  • Rank
  1. In the early stages of working on a game project using Visual Studio 2012 and OpenTK. What I'm working on right now, based on a series of tutorials I found, is a way to render text reliably. The general method I'm using is to create a Bitmap, draw the text to the Bitmap, then use it as a GL texture. The current method seems pretty inefficient (I'm recreating the bitmap every frame, I could probably split it into one smaller Bitmap per string and not have to constantly redraw them), but the problem I'm having is before that. After a few seconds of generating bitmaps, the program crashes. Code: [CODE] using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using System.Drawing.Text; using System.Linq; using System.Text; using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics.OpenGL; using OpenTK.Input; namespace FusionMan { class TextObject { public string text; public PointF pos; public TextObject(string nText, PointF nPos) { text = nText; pos = nPos; } } class Controller { Bitmap textBmp; int textTexture; Font font; List<TextObject> textObjects; // Called in OnLoad public void initialize() { // Initialize text rendering // Create Bitmap and OpenGL texture textBmp = new Bitmap(640, 480); // match window size PrivateFontCollection fontCollection = new PrivateFontCollection(); fontCollection.AddFontFile("fixed.ttf"); font = new Font( fontCollection.Families[0], 11, FontStyle.Regular); flushText(); } private void flushText() { textObjects = new List<TextObject>(); } public void addText(TextObject textObject) { textObjects.Add(textObject); textBmp.Dispose(); textBmp = new Bitmap(640, 480); // match window size textTexture = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, textTexture); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, textBmp.Width, textBmp.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero); // just allocate memory, so we can update efficiently using TexSubImage2D Graphics gfx = Graphics.FromImage(textBmp); gfx.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; foreach (TextObject t in textObjects) { gfx.DrawString(t.text, font, Brushes.White, t.pos); } BitmapData data = textBmp.LockBits(new Rectangle(0, 0, textBmp.Width, textBmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, 640, 480, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0); textBmp.UnlockBits(data); } private void drawText() { GL.LoadIdentity(); GL.Ortho(0.0, 640.0, 0.0, 480.0, 0.0, 4.0); GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha); GL.Color3(Color.White); GL.Begin(BeginMode.Quads); GL.TexCoord2(0f, 1f); GL.Vertex2(0f, 0f); GL.TexCoord2(1f, 1f); GL.Vertex2(640f, 0f); GL.TexCoord2(1f, 0f); GL.Vertex2(640f, 480f); GL.TexCoord2(0f, 0f); GL.Vertex2(0f, 480f); GL.End(); } // Called in OnRenderFrame public void draw() { flushText(); addText(new TextObject("Test", new PointF(10, 360))); drawText(); } } } [/CODE] Error message: [CODE] System.ArgumentException was unhandled HResult=-2147024809 Message=Parameter is not valid. Source=System.Drawing StackTrace: at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format) at System.Drawing.Bitmap..ctor(Int32 width, Int32 height) at FusionMan.Controller.addText(TextObject textObject) in c:\Users\algordon\Documents\Visual Studio 2012\Projects\FusionMan\FusionMan\Controller.cs:line 50 at FusionMan.Controller.draw() in c:\Users\algordon\Documents\Visual Studio 2012\Projects\FusionMan\FusionMan\Controller.cs:line 88 at FusionMan.SimpleWindow.OnRenderFrame(FrameEventArgs e) in c:\Users\algordon\Documents\Visual Studio 2012\Projects\FusionMan\FusionMan\Program.cs:line 61 at OpenTK.GameWindow.OnRenderFrameInternal(FrameEventArgs e) at OpenTK.GameWindow.RaiseRenderFrame(Stopwatch render_watch, Double& next_render, FrameEventArgs render_args) at OpenTK.GameWindow.DispatchUpdateAndRenderFrame(Object sender, EventArgs e) at OpenTK.GameWindow.Run(Double updates_per_second, Double frames_per_second) at FusionMan.SimpleWindow.Main() in c:\Users\algordon\Documents\Visual Studio 2012\Projects\FusionMan\FusionMan\Program.cs:line 72 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: [/CODE] it says "Parameter is not valid", but the line in question just says [CODE]textBmp = new Bitmap(640, 480); // match window size[/CODE] Any idea what's going on there?
  2. XNA Distribution Always Failing

    Tried what EJH suggested. Compiles and runs fine on my computer, but still suffers from exactly the same problem on other machines. Error is as follows: Description: Stopped working Files that help describe the problem: C:\Users\Li-Chi\AppData\Local\Temp\WER615.tmp.version.txt C:\Users\Li-Chi\AppData\Local\Temp\WER5252.tmp.hdmp Read our privacy statement: http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409 Not very useful, I know.
  3. XNA Distribution Always Failing

    Quote:Original post by EJH Also, are all your game IO file paths relative or absolute? That is the most common cause of distribution failure. Your paths should all be relative to the current directory the game .exe is running in. Currently, I'm using the provided features in VC#08 for adding content to the solution, and it doesn't give me the option of changing the filename, nor is there any indication of whether it's using relative or absolute paths. My code for loading the resource just says: mSpriteTexture = this.Content.Load<Texture2D>("hero"); Am I doing something seriously wrong here?
  4. I have spent all day looking up and trying different methods to distribute a .exe file of an XNA game. I made almost the simplest project possible (basically the XNA default game template with one picture added), and then tried the ClickOnce publish, and also tried using Nuclex's XNA installer to detect or install the XNA and .NET frameworks, and tried to have both people who DO have them already and people who don't, and it failed to work on both machines, despite working on mine. I am absolutely out of ideas as to why this isn't working, let alone how to make it work. I'm programming this on Vista, and I've tried using both Visual C# Express 2008 and SharpDevelop. If anyone has any further suggestions, I'm all ears.
  5. Side-by-Side Configuration Error

    Quote:Original post by Black Knight Are you using other libs in your project? The Linker page under properties lists "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib", and I've also included SDL.lib and SDLmain.lib.
  6. Side-by-Side Configuration Error

    All right, compiling as Multithreaded gives me the following errors: msvcrt.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) msvcrt.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj) msvcrt.lib(MSVCR80.dll) : error LNK2005: _exit already defined in LIBCMT.lib(crt0dat.obj) msvcrt.lib(MSVCR80.dll) : error LNK2005: _fopen already defined in LIBCMT.lib(fopen.obj) msvcrt.lib(MSVCR80.dll) : error LNK2005: _fclose already defined in LIBCMT.lib(fclose.obj) msvcrt.lib(MSVCR80.dll) : error LNK2005: __isctype already defined in LIBCMT.lib(isctype.obj) LIBCMT.lib(crt0init.obj) : warning LNK4098: defaultlib 'msvcrt.lib' conflicts with use of other libs; use /NODEFAULTLIB:library C:\...\arrow.exe : fatal error LNK1169: one or more multiply defined symbols found Any idea how to deal with that?
  7. Side-by-Side Configuration Error

    Quote:Original post by Black Knight The people you send should have this installed. Is there any way to distribute my program that doesn't require anyone getting it to download the redistributable package?
  8. I'm aware that this problem has been discussed before, but the solutions to those don't seem to be helping me, so I'll ask here. I am creating a C++ program using Visual Studio, and it runs fine on my computers (one running XP and one running Vista), but when anyone else tries to run it, they get the error message "The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more details." No application event log seems to be produced. I'm using Microsoft Visual C++, in Microsoft Visual Studio 2005: Standard Edition. I'm compiling in Release mode, using Multithreaded DLLs. What other information should I be providing?
  9. I'm just about to submit my latest game to the Independent Games Festival, and the submission form has a section on hardware requirements. How does one go about figuring this out? It's not a terribly taxing program - a moderate number of non-textured polygons and some bitmap fonts. The game can be downloaded at the URL below. Could anyone give me an estimate as to what I should list as the system reqs? http://professor.fireandrobot.com/zct.zip Thanks in advance.
  10. I dunno, on a (for example) 20x20 map, there's 400 tiles... storing the shortest path from every tile to every other tile would mean storing over 150000(!) values - 399 distances per tile!
  11. It being a pretty abstracted strategy game, effective gameplay challenge requires that the enemy, like you, always knows where you are.
  12. Actually, I am using A* for the pathfinding after it selects a target. But suppose there are 40 targets. Wouldn't it have to run the A* algorithm 40 times to find the closest one? If there are 40 humans and 40 zombies, that's about 1600 executions of A*, versus 40 executions of my algorithm. Is that really faster?
  13. I am working on a game (Titled Zombie City Tactics) that requires enemy AI more advanced than I'm used to working with. One particular thing is giving me trouble - the enemy units selecting the best target to approach. Take this situation, for example: http://img.photobucket.com/albums/v26/professorscissors/targetfind1.gif The green square representing the moving unit, the red squares representing potential targets, and the gray squares representing walls. Now, a stupid AI would assume the target on the left was better, because it's two squares away, whereas the other target is three squares away. However, a decently intelligent AI would see it like this: http://img.photobucket.com/albums/v26/professorscissors/targetfind2.gif And see that when it comes to actualy path length, the target on the right is much closer. My problem is that I'm trying to find a way to do this *quickly.* My current method should work, but gets very slow in large maps with lots of beings. What it does is this: http://img.photobucket.com/albums/v26/professorscissors/targetfind3.gif The yellow squares are the spaces it is looking at, because they are next to green squares. If it doesn't find any targets there, it marks the yellow squares as 'explored' squares, and iterates again: http://img.photobucket.com/albums/v26/professorscissors/targetfind4.gif Still no targets, so it iterates one more time: http://img.photobucket.com/albums/v26/professorscissors/targetfind5.gif And then it find the target on the right, and selects it. It wouldn't find the left target for another 3 iterations. If no new yellow squares are added in one iteration, it assumes no target and gives up. This works fairly well, but has the downside that it takes HUGE amounts of time in large, open areas. Can anyone here suggest a preferable method? Thanks in advance.
  14. OH! That's what the heap is. I've worked with it before, just not by name. The glDepthMask actually seems to have worked like a charm. I very much appreciate the suggestion - now I can actually get cracking on the rest of the project! Well, almost, anyways. I know that Particle *p; p = new Particle[MAX_PARTICLE] creates an array of particles, but how do you do this with a two-dimensional array? "map = new Tile[MAX_SIZE][MAX_SIZE]" generates a whole bunch of errors, top of the list being "Cannot convert from class Tile (*)[64] to class Tile *." If I change map from 'Tile *map' to 'Tile **map', then I still get that error, but the other 56 dissapear. This is shaky territory for me... I admit to not really knowing what I'm doing to much precision. All your help is appreciated.
  15. I've been working on a firefighter-based game in OpenGL, and I've run into a couple problems. One of them is GL-related and one isn't, so I figured I'd play it safe and post it in the general forum. 1: I'm having difficulty getting the particles for the fire effects to render properly. If I disable GL_DEPTH_TEST, then they render perfectly, except that I can see them through walls (screenshot). If I enable GL_DEPTH_TEST, then the blending doesn't work properly (screenshot). Is there any way to have both proper blending and proper depth testing? 2: The game world is tile-based, fairly large, and has to store numerous values in each Tile (fire strength, fuel, elevation, etcetera). Unfortunately, if I try and add any more information to the Tile class or make the map array any larger, then I get a stack overflow error. What would be a good workaround for this? Thanks in advance.