Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: 1 [2] 3   Go Down

Author Topic: Programming Q & A Round II  (Read 8693 times)

0 Members and 1 Guest are viewing this topic.
Re: Programming Q & A Round II
« Reply #20 on: February 12, 2011, 10:12:43 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Well, are you talking about parsing an image?  If so, the map format won't be necessary just yet.
Logged



i love big weenies and i cannot lie
Re: Programming Q & A Round II
« Reply #21 on: February 12, 2011, 11:19:04 pm »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
Let me try this question instead: Where would I begin to make a level editor similar to what I see users here make?
I am sure my previous question would be used with a level editor for a game so maybe that will give you a better understanding of what I am asking.
« Last Edit: February 13, 2011, 12:45:32 am by Theforeshadower »
Logged
  • Super Fan Gamers!

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #22 on: February 13, 2011, 12:11:13 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
OpenGL question:

How do I preserve the current buffer's contents? I am making a sort of painting program, so I need to preserve the canvas, but I also need to draw things on top of it that are not a part of the canvas. I have been looking at glReadBuffer, glReadPixels, but I do not know how to store the pixel data, then re-render it :<

Any help?
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #23 on: February 13, 2011, 05:36:50 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Xiphirx, I'll answer your question in a separate post


As for foreshadower...

In this case you're going to want to go through some planning stages before touching any code.  First thing I will advise you to do is to read up a bit on UML and the SDLC.  This will help you in your planning phases to determine what your program needs to do as well as how you're going to do it.  Now, once you've done that, you can move onto coding.  For this, I suggest C# with XNA to make it easier.  Do NOT use GDI, you'll go batshit insane when you try to run your program and start placing a large amount of tiles.

The primary concern here is tiling I'd assume.  You want to parse through your tileset image, just as you would parse through a string.  Base this on properties of the image, such as the dimensions of it and the dimensions of each tile.  You can grab pieces of the image by using the rectangle class, and then save that data in a buffer for later use.

Classes you'll want to look into from XNA:

Texture2D
Rectangle
spritebatch
Logged



i love big weenies and i cannot lie
Re: Programming Q & A Round II
« Reply #24 on: February 13, 2011, 05:41:12 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Xiphirx, there's no need to store the buffer itself.  This would be a pretty big DICK for game programming if we had to constantly copy buffer data (i.e. we put a buffer in your buffer so you can draw while you draw!).  Instead, simply store all objects that are to be drawn in a collection (List, LinkedList etc).  Each iteration of your program's main loop, just draw everything in that collection.  You can add additional drawings to your canvas by adding them to the collection when they're drawn.
Logged



i love big weenies and i cannot lie
Re: Programming Q & A Round II
« Reply #25 on: February 13, 2011, 05:46:48 am »
  • *
  • Reputation: +12/-2
  • Offline Offline
  • Gender: Male
  • Posts: 4849
Thanks , MG, I am going to look into those.  I do know bit about the XNA classes except the Rectangle one.  I will look into it.  I actually learned from your post about parsing itself so that is where I will start by learning information about parsing. 

Thanks again, man!
Logged
  • Super Fan Gamers!

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #26 on: February 13, 2011, 06:15:28 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Xiphirx, there's no need to store the buffer itself.  This would be a pretty big DICK for game programming if we had to constantly copy buffer data (i.e. we put a buffer in your buffer so you can draw while you draw!).  Instead, simply store all objects that are to be drawn in a collection (List, LinkedList etc).  Each iteration of your program's main loop, just draw everything in that collection.  You can add additional drawings to your canvas by adding them to the collection when they're drawn.

Thats the thing, it isn't a game that has objects that I can just draw whenever. It's a paint program, so you cant recreate the strokes.

I talked to people on an IRC about this and was told that FBO's were the way to go, however SDL+OpenGL (which is what Im using) doesnt support them, so I need to convert my code into native OGL code, which shouldn't be hard.
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #27 on: February 13, 2011, 06:23:42 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
Xiphirx. Can't you just setup a texture or bitmap that is your painting and each time you make a change to the painting, you actually make the changes to the texture/bitmap. And each time you have a screen refresh you render the texture/bitmap to the buffer. It is an application and not a game, thus speed and memory are less of an issue.

Unless you have a vector graphics painting, then you need to store the components.
Logged

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #28 on: February 13, 2011, 06:36:17 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
Apparently not with OpenGL, I have to draw to a separate buffer (FBO) and render that buffer, then the main buffer that I draw other things to.
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #29 on: February 13, 2011, 06:57:52 am »
  • *
  • Reputation: +9/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3725
I think OpenGL does have a buffer to texture rendering. And because actions are done only once in a few seconds and not every cycle you could load in the texture to the buffer, manipulate it and then render the buffer back to the texture. And use the texture in the display framebuffer. I don't have my OpenGL book here at hand but I guess the internet can tell you all about it. Just use google "OpenGL render to texture".

But MG probably knows a better and faster way of doing it.
« Last Edit: February 13, 2011, 07:42:01 am by Niek »
Logged
Re: Programming Q & A Round II
« Reply #30 on: February 13, 2011, 04:20:20 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
Ok, I did some research and the FBO (Frame Buffer Object) will be your best bet.  What you're basically going to do is create the object and bind it.  Once you've done that, you'll attach an image to it (i.e. your previous data, which I'd imagine you can grab using glReadPixels()) and then render as you normally would.  In this case, your image would probably be a renderbuffer rather than a texture.

Take a look here:
http://ogltotd.blogspot.com/2006/12/render-to-texture.html
http://www.songho.ca/opengl/gl_fbo.html <--This one is very detailed
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #31 on: February 14, 2011, 04:47:54 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
alright, I have implemented the code, but nothing is displaying...

Initialization
Code: [Select]
// -- Create FBO
//Create Rendering buffer
glGenRenderbuffersEXT(1, &flamesFBODepth); // Create render buffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, flamesFBODepth); // Bind the render buffer
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, sw, sh);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, flamesFBODepth);

//Create Texture
glGenTextures(1, &flamesFBOTexture);
glBindTexture(GL_TEXTURE_2D, flamesFBOTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sw, sh, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

//FBO
glGenFramebuffersEXT(1, &flamesFBO);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, flamesFBO);

glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, flamesFBOTexture, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, flamesFBODepth);

//Check if it was successfully created
GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
return false;

//Unbind...
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

Before I draw stuff that I'd like to go to my FBO
Code: [Select]
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, flamesFBO);
glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
glClearColor (1.0f, 0.0f, 0.0f, 1.0f);
glLoadIdentity();

Then its my rendering code, then

Code: [Select]
glPopAttrib();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Afterwards, when I want to render the FBO to the screen...

Code: [Select]
glBindTexture(GL_TEXTURE_2D, flamesFBOTexture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left

glTexCoord2f(1.0f, 1.0f);
glVertex3f(1.0f, 1.0f, 0.0f); // Top Right

glTexCoord2f(1.0f, 0.0f);
glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);

And nothing appears (hooray :|)... Any ideas as to what I'm doing wrong? :(
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #32 on: February 14, 2011, 10:44:43 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
I would say there's an error with your texture, but then you would at the least see a white box being drawn.  I'm going to say it's probably in the drawing code, because you used glTexCoord2f() for the texture coordinate, but you used glVertex3f() for your vertex coordinate.  You have a z-axis on your vertex, but not on the texture coordinate, so it has no idea what to do with the z axis.
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #33 on: February 15, 2011, 01:16:05 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
I replaced it with glVertex2d, but nothing...

I don't think the texture is invalid, if I put glClearColor(1.0f, 0.0f, 0.0f, 1.0f), it displays red... So I suppose its somewhat working? :/
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #34 on: February 15, 2011, 04:09:50 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
glClearColor() clears the buffer to whatever color you specify, so all you're doing with that is erasing everything and filling the screen.  Try drawing a primitive without applying a texture and see if you get anything.  Also, make sure you draw the vertices in the proper order (clockwise I believe).
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #35 on: February 15, 2011, 04:37:47 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
I actually got it to render "correctly"...

It renders lines, like it should, but the colors of every line change when each succeeding line's color should be changing only...

Its like, if I put one red line, then one green line, and then one blue line, it would show the red line fine, then it would show the green line along with making the red line green, and so on for the blue...

Why is this so hard :|



I had another question too, how do you resize (read: not scale) a texture?


Solved :3.

« Last Edit: February 15, 2011, 07:06:24 pm by Xiphirx »
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #36 on: February 15, 2011, 11:39:40 pm »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
What was the problem?
Logged



i love big weenies and i cannot lie

Xiphirx

wat
Re: Programming Q & A Round II
« Reply #37 on: February 16, 2011, 12:03:01 am »
  • Xiphirx
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3007
The first: I was applying the texture with alpha blending on, so ... yeah :P

Second: I didn't resize the depth buffer
Logged
  • For The Swarm
Re: Programming Q & A Round II
« Reply #38 on: March 05, 2011, 05:43:06 am »
  • Doesn't afraid of anything
  • *
  • Reputation: +42/-0
  • Offline Offline
  • Gender: Male
  • Posts: 7002
So thats it?  C'mon, there's no way you guys don't have more questions :P
Logged



i love big weenies and i cannot lie

Lunar

Former King
Re: Programming Q & A Round II
« Reply #39 on: March 05, 2011, 05:48:02 am »
  • Video Games
  • *
  • Reputation: +1/-4
  • Offline Offline
  • Gender: Male
  • Posts: 65
Is there a way to take a list of events from GM in drag-and-drop mode, and convert them into a script?

That would help -TREMENDOUSLY- in learning GML.
Logged
sup
Pages: 1 [2] 3   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.021 seconds with 73 queries.

anything