Insufficient understanding of 2D Viewports

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 2592 Views - Last Post: 15 December 2012 - 07:13 AM Rate Topic: -----

#1 Olebendz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-December 12

Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 04:54 AM

For about 4 months now I have been developing a very simple 2D game engine. Unfortunately and for obvious reasons, 3 weeks ago I came across a specific piece of information I needed to research on: how to build a 2D viewport in VB 2010 using either OpenGL or BASIC. Now, I feel like a noob and probably for good reason too, but I could not find any tutorials on how to go about making a 2D viewport with mouse scrolling capabilities. Are there actually any tutorials out there that guide individuals such as myself, step by step? I found plenty of articles and snippets of codes, but nothing that gave me a firm foundation of what I need to do. I've even went so far as to buy 'Game Engine Architecture by Jason Gregory' several days ago (I'm still waiting for it).

If you're wondering why I even began on starting to build a game engine without understanding viewports, then the answer is simple. Every programming skill I have learnt, I have learnt by setting myself VERY challenging tasks that involve skills that I do not have which therefor gives me consistent reason to do research on topics that I might not have thought of previously. I hope this has been enough information, if not, I will expand if needed.

Thus s,o can any please supply me with some links or references that could help me gain a better understanding of what I need to do?


Many thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Insufficient understanding of 2D Viewports

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 09:09 AM

Well, your approach is wrong. The key to programming games is to challenge yourself, but also to balance that with being able to make progress. If you are not making progress, you are stuck and not going anywhere in terms of you acquiring knowledge. So take it down a bit.

Anyway, give some example of what you have found in your research so we can pinpoint your problems.
Was This Post Helpful? 0
  • +
  • -

#3 Olebendz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-December 12

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:06 AM

I challenge myself with plenty of balance :) It's worked for me for the last 4 years. So far by building this, shall i say rather dire game engine, i have learnt a drastic amount that has kept me constantly drooling to learn more :)

I suppose everyone has their own methods of learning :)

Firstly;

1. I know I will not even attempt at building any viewport using the Visual Basics Programming language as that would just be wasting my time.
2. I know I will be using a combination of IronRuby and IronPython as they can work well with .NET.
3. I'll also use some OpenGL which i know can be used for 2D + look at using C# also.

Research:

1. I looked closely at nehe.gamedev which provided a useful tutorial on multiple viewports and I got the basic principles of creating a viewport from this, however the tutorial was made for 3D viewports and not 2D. I looked closely at the coding and I couldn't determine how to re-write it as 2D. I have a thousand and one excuses as to why, but the underlying reason is that I can't grasp of how to implement it into Visual Basics 2010.NeHe Multiple Viewports

2. I looked closely at the GLCanvas, but the most I found were snippets of the code and nothing explaining the building blocks of the canvas.

3. I found plenty of information on creating viewports in Vectorworks, unfortunately I can't afford that software.

4. I discovered XNA scripting can work with Visual Basics 2010 also.

See the thing is, there is lots if information out there, plenty of snippets and articles and i've read as many as my eyes can manage! Yet there is nothing, from what I can find, that gives clear precise building blocks on how viewports work. If I knew what the building blocks were, then I'd know where to start scripting. Yet, i'm at a complete loss :/
Was This Post Helpful? 0
  • +
  • -

#4 Olebendz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-December 12

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:12 AM

I forgot to mention, which I should have done earlier, that i'm not after any coding or 'free' scripts. I am simply looking for a website or article or tutorial in general that breaks up the process of building a viewport and explains each section in detail in what they do. Again, the building blocks of the viewport, that's really all i'm dying to find! :(
Was This Post Helpful? 0
  • +
  • -

#5 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:15 AM

I wouldn't really think of 2D viewports in the same way as 3D ones. All you are really doing is defining the drawable area, you can copy a portion of a loaded image into a rectangle ("viewport"). scroll the mouse moves the rectangle on the source image and copies that portion to the destination ("viewport").
Was This Post Helpful? 0
  • +
  • -

#6 Olebendz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-December 12

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:18 AM

Is it really that simple? :o
Well, i shall give it a go! Thank you :)
Was This Post Helpful? 0
  • +
  • -

#7 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:21 AM

That's how I would do it. What kind of game are you making?
Was This Post Helpful? 0
  • +
  • -

#8 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 10:57 AM

I wouldn't be inclined to liken a viewport to a 'drawable area', it's a viewable area since the area that can be drawn to is normally bigger than the viewable area.

Certain principles from 2D and 3D are transferable. You may want to review Orthographic Projection which is transforming a 3D scene for rendering on the 2D screen matrix. I know that you are working in 2D, but once you get this it might give you further ideas for your game.

Secondly, depending on what you're trying to achieve like finding the perpendicular vector to another where the calculation is only defined in 3D space, you could have the third axis normalized to unity and make use of orthographic projection techniques to render on your 2D surface.

There are no real tutorials on this. Good going with getting the book and I hope you resolve your challenges. :)/>

This post has been edited by ButchDean: 12 December 2012 - 10:58 AM

Was This Post Helpful? 0
  • +
  • -

#9 Olebendz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 12-December 12

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 11:03 AM

Well, i've actually been building a game engine. A very dire one, but so far, so good. Posted Image

Well, I tried the viewport method you suggested; unfortunately it didn't really do anything. Not what I need anyhow.

The game that I want to make with it is a simple 'Sticks and Stones' game. Nothing to complicated.
You have a stick, Stones come down from above and you need to hit each one out of the way. For each successful hit, you get +1 point, for each failed hit you get -1 point. Each level gets faster and harder.

I will definitely do some studying on Orthographic Projection and the techniques!
And I will look into normalizing the third axis :)
Thank you both for your help :)
Was This Post Helpful? 0
  • +
  • -

#10 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 01:51 PM

View PostButchDean, on 12 December 2012 - 05:57 PM, said:

I wouldn't be inclined to liken a viewport to a 'drawable area', it's a viewable area since the area that can be drawn to is normally bigger than the viewable area.


You wouldn't really draw outside of the viewable area, at least that's not how I do things. The window is the viewable area and also the dimensions of what i am drawing to. I have just done this in an SDL 2.0 game I am making. The source rectangle is a section of a loaded image, the data within this area is copied to a rectangle (the renderer) the exact dimensions of the window, when the character moves the background appears to scroll but all it is really doing is moving the source rectangle and copying the data from within its new position.

I could of course load a big level that can then be moved around, but since i am copying the data each frame anyway it eliminates the need for this by only rendering what is needed.
Was This Post Helpful? 0
  • +
  • -

#11 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 02:14 PM

The reason why we have clipping planes is that we only draw in the view volume. This is not the same as the drawing surface being the view volume. I hope this is clear.
Was This Post Helpful? 0
  • +
  • -

#12 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 02:32 PM

I see. You are thinking in 3D whereas I am not.
Was This Post Helpful? 0
  • +
  • -

#13 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Insufficient understanding of 2D Viewports

Posted 12 December 2012 - 03:53 PM

Well, 3D vs. 2D - is there a difference with what the definition of a draw surface is? Irrespective of how you implement a draw surface, be it the same size as the view port or not, the fact remains that they can be different sizes and are treated very differently. The view port restricts what can be seen, whereas the draw surface allows you define the scene in terms of all viewable assets and their relative positions. They just aren't the same no matter how much you try to spin it.

This post has been edited by ButchDean: 12 December 2012 - 03:54 PM

Was This Post Helpful? 0
  • +
  • -

#14 stayscrisp  Icon User is offline

  • フカユ
  • member icon

Reputation: 1009
  • View blog
  • Posts: 4,197
  • Joined: 14-February 08

Re: Insufficient understanding of 2D Viewports

Posted 13 December 2012 - 02:19 AM

Spin it? I am merely pointing out what I have implemented. If you are using a scrolling background in 2D then you are essentially using the viewport as the drawable area, drawing outside it would be inefficient. That said it makes things easier to think of the viewport as the drawable area, as that is the only area you are going to draw to. You are still thinking of a view port as a projection rather than as a drawable surface which is essentially what it is when scrolling a 2D background. I don't really see how you think this is wrong.

The OP's original question was about scrolling his maps and essentially creating a 2D camera (don't take that in the 3D way). This can be achieved by having your background draw surface do exactly as I have described with the "viewport" or camera if you will being a draw surface.
Was This Post Helpful? 0
  • +
  • -

#15 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5882
  • View blog
  • Posts: 12,760
  • Joined: 16-October 07

Re: Insufficient understanding of 2D Viewports

Posted 13 December 2012 - 03:42 AM

I agree with both of you. :P Let me try.

A viewport is, essentially, a virtual abstration that defines a point of view in an even more virtual abstraction.

It makes more sense in 3D. In a 3D environment you have to define all your objects in a 3D model that doesn't have much to do with graphics yet. Some of those objects are curious things like light sources. It is true 3D, x, y, z, but the screen ain't. So you pick a point in 3D space, a plane in 3D space, onto which all the visualable object will be squished. A viewport.

Now, in your classic 2D, Mario, sprite environment, you have none of that. Sprites are just drawn, not rendered based on POV. There might be some z-order, but that's about it; the images stay the same. A viewport in such an environment can be seen as a clip plane. Or... well, think about it. You don't need to define a 3D environment but you still need to track all those sprites, many of which aren't going to be in that clipping area. Your viewport defines the visiable part of that 2D, not even drawn yet, model.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2