• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

130 Neutral

About Mellkor

  • Rank

Personal Information

  • Interests
  1. Hi,    Trying to write a wrapper for a lua virtual machine object that will register functions but am having trouble passing a function pointer parameter to it. The idea is to pass something like, "Foo.Go" to RegisterFunction and that will associated it with the lua_state member of the virtual machine class.   This is what i have: void LuaVM::RegisterFunction(const char* name, lua_CFunction functionName) { lua_register(getState(), name, functionName); } I'm getting the error: "a nonstatic member reference must be relative to a specific object", Any ideas on how to tackle this?    
  2. Spritebatch With SharpDx

      Thanks, But still no dice   Also, When i try:   graphics.Clear(new Color4(1, 0, 0, 0)); instead of using the context, it says i'm missing a "presenter" Could it be when i initialized the sprite batch and passed the device without a presenter its causing the problem?
  3. Starting as a game programmer

      Hi,   My first post as "advice" so take it as a grain of salt.. Been studying programming for 2 years, Ive "Learned" (although you never stop learning)' C#, Java, Objective-C among other things.. and ive self taught C++ The theory doesn't change: Inheritance, polymorphism, ect just the implementation does. So jump into a language you are most comfortable with because those skills you learn will be portable.   I am personally a fan of C# and although not a recent article C# can get apparently pretty close in DX vs c++. Source
  4. Spritebatch With SharpDx

      Sorry for the late reply,    Still can't seem to get it to work, I have tried the following line of code: context.Rasterizer.SetViewport(0.0f, 0.0f, 512.0f, 512.0f); But that seems to make no difference.   I mainly only use xna for my 2d games and only dabble in Dx and Opengl.. so any help or links to tutorials to get this working would be a great help.   Thanks.
  5. Spritebatch With SharpDx

    Hi, I am trying a little experiment to render a simple image using the Spritebatch with SharpDX I get the BlueCornflower clear But no Image.. Debug says that the file has been successfully loaded so i'm guessing its to do with the Device setup which i am not very familiar with.   Thanks using System; using SharpDX; using SharpDX.Direct3D; using SharpDX.Direct3D11; using SharpDX.DXGI; using SharpDX.Windows; using Buffer = SharpDX.Direct3D11.Buffer; using Device = SharpDX.Direct3D11.Device; using Texture2D = SharpDX.Direct3D11.Texture2D; using SharpDX.Toolkit.Graphics; namespace TestDriver { static class Program { [STAThread] static void Main() { RenderForm form = new RenderForm("Demo"); var desc = new SwapChainDescription() { BufferCount = 1, ModeDescription= new ModeDescription(512, 512, new Rational(60, 1), Format.R8G8B8A8_UNorm), IsWindowed = true, OutputHandle = form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput }; // Create Device and SwapChain Device device; SwapChain swapChain; Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, desc, out device, out swapChain); var context = device.ImmediateContext; var backBuffer = SharpDX.Direct3D11.Texture2D.FromSwapChain<SharpDX.Direct3D11.Texture2D>(swapChain, 0); var renderView = new RenderTargetView(device, backBuffer); GraphicsDevice graphics = GraphicsDevice.New(device); SpriteBatch spriteBatch = new SpriteBatch(graphics); string path = "image.dds"; var image = Texture.Load(graphics, path,TextureFlags.ShaderResource, ResourceUsage.Immutable); var rectangle = new Rectangle(100, 100, 980, 272); RenderLoop.Run(form, () => { context.ClearRenderTargetView(renderView, Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(image,rectangle,Color.White); spriteBatch.End(); swapChain.Present(0, PresentFlags.None); }); } } }
  6. C++ XML Serialization

    As a learning exercise to get more familiar with C++, I'm trying to Serialize a class to xml but finding its quite intimidating than what i'm used to with c#..   Header File for the "Model". class Level : public DrawableObject { public: std::vector<Sprite> spritelist; int sizeX; int sizeY; int tileSize; Level(); }; What would be ideal is to have a library come in and have a look at the class and convert each field it to xml. (which apparently would be to much to hope for lol).   My major concern with trying to manually specify what to serialize is when it comes to the spritelist vector that it wont serialize the Sprite Classes.   Does anyone have any suggestions to frameworks and implementations?.
  7.   Using c++ and gcc, It works and compiles now. Thanks a bunch    After actually reading and understanding the code(learnt some new tricks), it wasn't quite what i was after i was hoping to define a triangle with 3 vertices and a color. and use an iteration for loop to make more triangles, not make a triangle out of an iteration of vertices like you posted   Something like this maybe: for (int i = 1; i < 6; i++) { //Orthographic triangle {0xFF0000FF, -0.0f*i, -0.0f*i, 0.0f}, {0xffffff00, 0.0f*i, 50.0f*i, 0.0f}, {0xFF00FF00, 50.0f*i, 0.0f*i, 0.0f}, } If you have time to offer some more assistance that would be excellent, if not thanks again
  8.     Thanks for your reply!, Going through your code now. Getting some build errors atm.   "error : expected '=', ',', ';', 'asm' or '__attribute__' before 'vertices' "? Edit: fixed the error by putting back in the "struct" - program now compiles and draws a single vertical line down the screen lol.       Question: Curious about the theory you used to here, They are defined as type INT, but the member uses a float arguement? -  int xVal[3] = {0.0f, 0.0f, 50.0f}; int yVal[3] = {0.0f, 50.0f, 50.0f}; int zVal[3] = {0.0f, 0.0f, 50.0f};
  9. Hi,    Experimenting more with c++, but have encountered a problem i cant solve. (driving me mad lol) The program runs perfectly with this code, Drawing a Triangle. struct Vertex { unsigned int color; float x, y, z; }; struct Vertex vertices[3]= { {0xFF0000FF, -0.0f, -0.0f, 0.0f}, {0xffffff00, 0.0f, 50.0f, 0.0f}, {0xFF00FF00, 50.0f, 0.0f, 0.0f}, //{0xffffff00, 0.0f, 50.0f, 0.0f}, //{0xffffff00, 50.0f, 50.0f, 0.0f}, //{0xffffff00, 50.0f, 00.0f, 0.0f} }; vertices are passed off to the drawcall at the end, Everything works fine.   But i'm trying to "build" the verticies in a loop. The goal is to eventually build a tilegrid out of the vertices, and push them all at the drawcall.    I Can get the solution to compile but, alas no triangle. struct Vertex { unsigned int color; float x, y, z; }; struct Vertex vertices[3]; struct Vertex *pVerticies = &vertices[0]; void BuildVerts(struct Vertex *pVerticies) { int i; for (i = 0; i < 1; i++) { (pVerticies+i)->color = 0xFF0000FF; (pVerticies+i)->x = 0.0f; (pVerticies+i)->y = 0.0f; (pVerticies+i)->z = 0.0f; (pVerticies+i)->color = 0xFF0000FF; (pVerticies+i)->x = 0.0f; (pVerticies+i)->y = 50.0f; (pVerticies)->z = 0.0f; (pVerticies+i)->color = 0xFF0000FF; (pVerticies+i)->x = 50.0f; (pVerticies+i)->y = 0.0f; (pVerticies+i)->z = 0.0f; } } int main(int argc, char* argv[]) { BuildVerts(pVerticies); ... I suspect that i'm not using pointers correctly or i need to initialize array elements 'inline' like ie verticies = {..,}; ?
  10. 2D tilemaps "Chunk Theory".

      Thanks mate! ill have take a look over the drawings and code.
  11. 2D tilemaps "Chunk Theory".

      Yes, I understand that in theory, and that's what i'm trying to accomplish but its the implementation theory that's my problem.   If I have a chunk that is 50x50 tiles big, The player/camera gets to local tile 30,0 and wants to load the next chunk(next set of 50x50 tiles), How do i know where to start drawing the next chunk?
  12. 2D tilemaps "Chunk Theory".

    This is my very simple attempt at drawing a single chunk, Its probably horribly inefficient and "incorrect" lol public class Game1 : Game { //Chunksize int width = 10; int height = 10; //tilesize int tSize = 64; GraphicsDeviceManager graphics; SpriteBatch spriteBatch; public static Texture2D texture; //Chunks chunk[] ChunkArray = new chunk[5]; //Tile public class tile { public Texture2D texture; } //chunk public class chunk { public tile[,] tiles; public chunk() { this.tiles = new tile[5, 5]; BuildChunk(); } public void BuildChunk() { for (int x = 0; x < 5; x++) { for (int y = 0; y < 5; y++) { this.tiles[x, y] = new tile(); this.tiles[x, y].texture = Game1.texture; } } } } private void addChunkToArray() { ChunkArray[0] = new chunk(); } public Game1() : base() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { // TODO: Add your initialization logic here base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); texture = Content.Load<Texture2D>("tile.png"); addChunkToArray(); // TODO: use this.Content to load your game content here } protected override void UnloadContent() { // TODO: Unload any non ContentManager content here } protected override void Update(GameTime gameTime) { base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); //foreach (var chunk in ChunkArray) for (int ci = 0; ci < ChunkArray.Length; ci++) { { if (ChunkArray[ci] != null) { foreach (var tile in ChunkArray[ci].tiles) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { spriteBatch.Draw(tile.texture, new Rectangle(x * 64, y * 64, tSize, tSize), Color.White); } } } } } spriteBatch.End(); base.Draw(gameTime); } } } }  My next goal was to set up another chunk to the right of that one using the array, but it seems from your post that i should pretty much reevaluate the whole theory?
  13. 2D tilemaps "Chunk Theory".

    Hello!   I'm looking to get as much theory as possible on this subject, I have a hobby project i'm working on: a 2D orthographic game which i have used the standard tile grid array technique to render in XNA. But would like to implement dynamic loading of groups of tiles (chunks) so i can implement larger worlds then a standard grid.   The part of the theory i most understand is when the camera, or object gets close to the edge of a chunk the new one is loaded in the direction the camera is traveling and the chunk behind is unloaded. I guess the theory is to have an array that tracks chunks, then another array inside the chunk to track tiles?   Things I don't understand: Loading an adjacent chunk that "lines up" with the old one. Best way to "signal" a new chunk should be loaded. General Implementation details   I would like to heavy research this topic as i want it to be a center point of any other 2d games i make in the future. So i welcome any and all recommended: Books Tutorials Videos And of course code snippets and comments would be very valuable to me. (most proficient with XNA)   Thanks.   Edit: (Also had another question on general tile maps, should i ask here or start a new thread)?
  14. From C# to C++ concept questions..

      My understanding is:   The stack, is a division of memory which is quite small in relation to the heap. Variables are pushed on to the heap when they are needed and removed when they go out of scope.(ie when a function ends)   The heap on the other hand is a large container of memory that is managed by the programmer. the Heap holds (or should) variables that have a long life cycle or quite large in size.   In my initial post, I did kinda ask in a roundabout way if you could crash a program by filling up the stack. and if you should strategically offload to the heap
  15. From C# to C++ concept questions..

        Ah ok, Thanks again.
  • Advertisement