EDITT: MarauderIIC I need help, YOURS because...

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

EDITT: MarauderIIC I need help, YOURS because...

Post by MadPumpkin »

MarauderIIC I need help, YOURS because I've already seen how you do it xD

well to make a long story short... i need help in C#!!!
im making a level editor called orange and i don't know how to make a portion for rendering all of the tiles
for example...
i have the program, their is 2 "docked navigator" with buttons and such, 1 docked on top and 1 on right
the rest of it is... well thats where i need your help... i want to make the rest of it render my tiles and that will be the editing section as well...obviously...

so would you like to let me know how?? like... do i need a panel in that area? or some other form?? or just raw programming mad skillz? im not very advanced w/ C# ima C++ typa person

EDIT: By the way i don't ONLY want Marauder's opinion! any opinion or way of doing so would be pretty sweet
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by thejahooli »

I'm needing help with this too.
Preferably C# forms but even if anyone know how to do it in C++ forms I will be grateful.
I'll make your software hardware.
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by RyanPridgeon »

I believe a good easy way to do it would to be using a picture box.

This is basically a bitmap on the form that you can draw onto :P

I haven't used it in C#, but I used it on VB.net, and I've used other parts of forms on C# and it all seems similar.
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by MarauderIIC »

RyanPridgeon wrote:I believe a good easy way to do it would to be using a picture box.
I used this approach but ran into problems; possibly because I was making the bitmap the size of the map in order to use the autoscroll property of the panel that the picture box was contained in. Now I use a hardware-accelerated approach for the viewport, but I still use this bitmap approach for the tile selectors on the right hand side.

For the viewport, I use OpenTK ( http://www.opentk.com ) which is a free toolkit. It provides a user control called GLControl that you can place on a form, and that area is rendered by OpenGL. I have a user control that inherits from GLControl, called Viewport, which is placed on the main form (actually, it's placed on my tabcontrol so that I can eventually edit multiple maps at once, but that's a different story). The map is rendered in the Viewport control. To render the map, I use the standard OpenGL approach that is used whenever you render an image from a tile sheet (loop through map data which tells us which tile should be drawn, get this tile from the correct area on the tile sheet using a set of stored rectangles, draw this tile at the appropriate area on the viewport). The scrollbars actually have maximums defined by the size of the map minus the size of the viewport, and they scroll one tile at a time. They cause the Viewport to do a glTranslate, I think. So the viewport is no bigger than what you see, but the scrollbars scroll the image that the viewport displays. This approach could probably be used with PictureBoxes to decent effect, too, but redrawing would be slower.

Does that answer your question, or do you need more?
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by thejahooli »

Thanks.
I'll probably not use it for now because I haven't done any OpenGL so I'll probably make my own simple GUI using SDL in C++ for my level editor.
I'll make your software hardware.
User avatar
RyanPridgeon
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 447
Joined: Sun Sep 21, 2008 1:34 pm
Current Project: "Triangle"
Favorite Gaming Platforms: PC
Programming Language of Choice: C/C++
Location: UK
Contact:

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by RyanPridgeon »

MarauderIIC wrote:I used this approach but ran into problems;
Just out of interest, what problems did you run into?
Ryan Pridgeon
C, C++, C#, Java, ActionScript 3, HaXe, PHP, VB.Net, Pascal
Music | Blog
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by MadPumpkin »

thanks to you all for your very quit replies! and thanks marauder for your link to OpenTK im going to start learning it once i come back home from my chickky friends haus xD
but... i don't know much C# anyways... so a bit of code and an explaination of where it goes would be VERY useful on this
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
User avatar
M_D_K
Chaos Rift Demigod
Chaos Rift Demigod
Posts: 1087
Joined: Tue Oct 28, 2008 10:33 am
Favorite Gaming Platforms: PC
Programming Language of Choice: C/++
Location: UK

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by M_D_K »

mainly mem usage and CPU power needed for it to run smooth. Since the picture box isn't hardware accelerated.
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by thejahooli »

Do you know any good tutorials for it.
I can't get the tutorials on the website to work for me, probably because I forgot to include a file or something stupid but the tutorials fo not explain well
I'll make your software hardware.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by dandymcgee »

If you guys have never made any sort of editor before I would definitely recommend you start off with SDL or OpenGL, just drawing the tiles in a window. It's much less complicated and doing it on some sort of form. Once you can do that, you can essentially use the same code along-side a GUI. If you've done this and were just wondering what Mar used (I asked the exact same question recently, so you didn't search the forums very well in the first place ;) ), then disregard this post.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
User avatar
thejahooli
Chaos Rift Junior
Chaos Rift Junior
Posts: 265
Joined: Fri Feb 20, 2009 7:45 pm
Location: London, England

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by thejahooli »

dandymcgee wrote:If you guys have never made any sort of editor before I would definitely recommend you start off with SDL or OpenGL, just drawing the tiles in a window. It's much less complicated and doing it on some sort of form. Once you can do that, you can essentially use the same code along-side a GUI. If you've done this and were just wondering what Mar used (I asked the exact same question recently, so you didn't search the forums very well in the first place ;) ), then disregard this post.
I'm doing my level editor in SDL now but I would still like to know about using this with C# forms in case I want to use them in something else.
I'll make your software hardware.
User avatar
MarauderIIC
Respected Programmer
Respected Programmer
Posts: 3406
Joined: Sat Jul 10, 2004 3:05 pm
Location: Maryland, USA

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by MarauderIIC »

RyanPridgeon: M_D_K got the problems I ran into 100% accurate. PictureBoxes are slow when they get big, and redrawing them isn't fast, either.
dandymcgee wrote:If you guys have never made any sort of editor before I would definitely recommend you start off with SDL or OpenGL, just drawing the tiles in a window. It's much less complicated and doing it on some sort of form.
Actually, with the GLControl, drawing the map is exactly the same as drawing the map outside of a form, in a normal OpenGL window. With that out of the way,
MadPumpkin wrote:a bit of code and an explaination of where it goes would be VERY useful on this
I don't want to teach you OpenGL basics here, so here's some summary followed by the only code that you won't find on NeHe:

I got OpenTK, and made a "public partial class Viewport : GLControl", which I then placed on my form.

For initialization, look @ NeHe's tutorial on Orthographic projection, or read the documentation on glOrtho (OpenTK: GL.Ortho)
My initialization uses GL.MatrixMode, GL.LoadIdentity, GL.Ortho and GL.Viewport (I'm pretty sure I just copied this bunch out of the tutorial on opentk.com).

Drawing the map is just iterating through my list of tiles and drawing the correct one from the tile sheet. The tile that the map has can be used as a direct index into the tilesheet's list of rectangles, when the tilesheet is loaded left to right top to bottom.

To draw, it's just the calls you can find in the tutorials on texture mapping with a tile sheet. Mine enables Texture2D, AlphaTest, uses Greater for the alpha function, and sets color to (1.0, 1.0, 1.0, 1.0) using GL.Color4(). My GL.Translate takes into account the values of my scroll bars.

The only thing that really differs from standard OpenGL techniques is the tile sheet loading, so here's that, with some parts edited out.

Code: Select all

        public TileSheet(string imageLocation)
        {
/* do some parameter validation... */
/* set some defaults... */
/* save the image location... */

            Bitmap sheet = new Bitmap(imageLocation); //TCR: Load the sheet's image so we can load it into opengl

/* save sheet width and height... */

            TilesHigh = SheetHeight / TileHeight;   //FIXME: Default value only; needs to load from file
            TilesWide = SheetWidth / TileWidth; //FIXME: Default value only; needs to load from file

/* Class "Tile" is pretty much just Rectangle with some extra class members that I found useful during map editing.
So this is just a glorified list of Rectangles. */
            Tiles = new List<Tile>(TilesHigh * TilesWide); 

            this.ID = GL.GenTexture();
            GL.BindTexture(TextureTarget.Texture2D, this.ID);

/* Copied this next bit from OpenTK forums. It probably does what you think it does. */
            BitmapData data = sheet.LockBits(new Rectangle(0, 0, sheet.Width, sheet.Height),
                ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.PixelFormat.Bgra,
                PixelType.UnsignedByte, data.Scan0);
//            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Replace);
            GL.Finish(); /* Finish guarantees that the file is not being held by OpenGL, otherwise we get occasional exceptions during the next call */
            sheet.UnlockBits(data); /* Copied this from OpenTK forums ... */

            sheet.Dispose(); /* Get rid of our Bitmap, it's a memory hog */
            sheet = null; /* Ensure no references so the garbage collector doesn't get confused */
            data = null; /* Same for its data */

/* Do some standard NeHe stuff */
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
                (int)TextureMinFilter.Linear);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
                (int)TextureMagFilter.Linear);

/* Increment tile cut-out coordinates by the size of a tile, where "1.0" is the size of the sheet. */
            float uInc = (float)TileWidth / (float)SheetWidth;
            float vInc = (float)TileHeight / (float)SheetHeight;
            float u1, v1, u2, v2;

            for (int y = 0; y < TilesHigh; ++y)
            {
                for (int x = 0; x < TilesWide; ++x)
                {
                    u1 = uInc * x;
                    v1 = vInc * y;

                    u2 = uInc * x + uInc;
                    v2 = vInc * y + vInc;
                    Tile t = new Tile(u1, v1, u2, v2);
                    Tiles.Add(t);
                }
            }
MadPumpkin: Let me know if you need more. I don't really want to teach you C# basics, either. :) You'll find it's a lot like C++ combined with Visual Basic.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
User avatar
MadPumpkin
Chaos Rift Maniac
Chaos Rift Maniac
Posts: 484
Joined: Fri Feb 13, 2009 4:48 pm
Current Project: Octopia
Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
Programming Language of Choice: C/++,Java,Py,LUA,XML
Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk

Re: EDITT: MarauderIIC I need help, YOURS because...

Post by MadPumpkin »

thank you very much again everyone! ima start adding that to my code xD
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
Image
Image
Image
Post Reply