Jump to content

  • Log In with Google      Sign In   
  • Create Account

Mellkor

Member Since 04 Nov 2009
Offline Last Active Oct 30 2014 01:35 AM

Topics I've Started

Spritebatch With SharpDx

21 October 2014 - 03:42 AM

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);
            });
        }
    }
}



C++ XML Serialization

31 May 2014 - 10:42 AM

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?.


Pointer, array and struct problem?..

10 February 2014 - 05:36 PM

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 = {..,}; ?


2D tilemaps "Chunk Theory".

06 February 2014 - 05:46 PM

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)?


From C# to C++ concept questions..

18 December 2013 - 09:11 AM

Hi,

 

I Know my way around the C# language fairly well and am looking to try and 'break into' doing some c++ but have a few conceptual questions to ask.

 

My main questions are about pointers and memory management, I believe i have researched and understood what pointers are, and how to use and manipulate them but i do not clearly understand why to use them.

 

C# Example:

 

class Program
    {
        static void Main(string[] args)
        {
            List<int> numberArray = new List<int>();
            Random rnd = new Random();
 
            for (int i = 0; i < 10000000; i++)
            {
                numberArray.Add(rnd.Next());
            }
        }
    }
 
Now, this code should fill a dynamic array allocating memory as needed but when the variable goes out of scope it should be sent to the GC and eventually destroyed correct? 
 
Now, if the same program were to be written in c++ using 'identical code' (ie not pointers) then that array would fill up the stack and the program should crash right?
 
That's why you need pointers? to send large or persistent data to the heap and not overload the stack?

PARTNERS