Topic: Drawing in Orthographic mode

I'm trying to do some orthographic drawing and everything's looking squashed and in the wrong place. I have no idea what I've managed to set up incorrectly.

Oh, and another thing is that for some reason the setup that I assumed would be right, gave {0,0} at the bottom left (huh?)

unsigned int w, h;
system->getScreenSize(&w, &h);
render->setOrthoView(0, w, h, 0, 0.1, 1);

render->enableVertexArray();
render->enableTexCoordArray();
//...

I did also have render->setViewport(0,0, w, h); in there to test, but it did nothing.
The vertices I'm trying to draw are two quads from {0,0} to {200,200} and {100,100} to {300,300}.

http://img26.imageshack.us/img26/3357/squashed.png

Any ideas?

Last edited by Nistur (2012-09-06 07:15:05)

Re: Drawing in Orthographic mode

Hi,

you have to set the viewport and the matrix, like with openGL :

void set2dMode(unsigned int width, unsigned int height)
{
    MRenderingContext * render = MEngine::getInstance()->getRenderingContext();
    render->setViewport(0, 0, width, height);
    
    // set ortho projection
    render->setMatrixMode(M_MATRIX_PROJECTION);
    render->loadIdentity();
    
    render->setOrthoView(0.0f, (float)width, (float)height, 0.0f, 1.0f, -1.0f);
    
    render->setMatrixMode(M_MATRIX_MODELVIEW);
    render->loadIdentity();
}

(used in the post process example : http://www.maratis3d.com/code/post-process/MyGame.cpp)

Re: Drawing in Orthographic mode

... I'm sorry... clearly my mind wasn't working well this morning.

Thanks smile

Re: Drawing in Orthographic mode

It's working ?

Re: Drawing in Orthographic mode

((sorry for the delay, I had to wait until my lunch break to actually test it))

No, it's actually rendering nothing at all now smile But I'm quite happy to say that it's probably some of the crazy things I'd tried to get the thing displaying properly before that I haven't un-done yet. I will fiddle more tonight smile

Re: Drawing in Orthographic mode

If you want to draw 2d, you might also need to disable depth-test and face-culling.

Re: Drawing in Orthographic mode

Thank you, that worked great. Here's the beginning of a "dialogue box", this one is particularly smiley. And the stretching in this case is on purpose. Now to hunt for textures

http://img96.imageshack.us/img96/5779/smilekg.png

Re: Drawing in Orthographic mode

It worked great. I had a little problem with my atlas implementation to get it to display properly, but tadaa! Now I can go on and make more GUI stuff smile
http://img41.imageshack.us/img41/6936/boxgx.png

Yes, I know that the top left image is 1px larger than the rest, I will sort that

Re: Drawing in Orthographic mode

Looks nice smile
Are you doing an in-game GUI system ?

Re: Drawing in Orthographic mode

I will probably end up using it for that too, yep smile To begin with (because the design is far simpler than complex game GUI) it's for the tools stuff I'm doing, but I am trying to write it in a way that's easy to reuse for ingame stuff.

All of the layout and logic is actually a collection of lua classes, there's very little actually implemented in C++ right now (the atlasing system and RendererDrawQuad is really all it is)

Over lunch, I reused the atlas system to do bitmap font rendering using the same setup. I should be able to do any dialogue box with 2 draw calls with no optimisations, if it ends up being slow (really shouldn't) then I could probably make it ~2 draw calls for the whole GUI.

Re: Drawing in Orthographic mode

Very nice smile

For the text you can also use MOText manually I think, but there might be a little trick for drawing it if it's not in a scene (not sure).

Re: Drawing in Orthographic mode

I had a quick look at MOText, I just used the atlas system because I knew I could get it working quickly. I think I might get it to fallback on MOText, if I have time, I don't know.

There's a lot of GUI-ish things that still need to be done, like animations... but for now I think, with the exception of keyboard and mouse input, I'm almost done with GUI features.