• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
FuraProject

GL Matrix Stack issue

6 posts in this topic

Hello!

Recently i stumbled upon one issue. It took me few hours to find out why form is displaying some elements wrongly. I found that issue out, but i don't understand problem in my code.

Here is the code part that i have problem with. I use LWJGL.

[source lang="java"]
GL11.glPushMatrix();

// first translate
GL11.glTranslatef(100, 0, 0);

GL11.glPushMatrix();

//second translate
GL11.glTranslatef(0, 100, 0);

// first object
GL11.glPushMatrix();
glColor4f(1f, 1f, 1f, 1);
GL11.glTranslatef(UI_Form_CONFIG.FORM_HEADER_MARGIN_MOVE, UI_Form_CONFIG.FORM_HEADER_MARGIN_MOVE, 2);
GL11.glScalef(UI_Form_CONFIG.FORM_HEADER_BORDER_WIDTH, UI_Form_CONFIG.FORM_HEADER_BORDER_HEIGHT, 0);
drawQuad();
GL11.glPopMatrix();

//second object
GL11.glPushMatrix();
glColor4f(1f, 0f, 0f, 1);
GL11.glTranslatef(UI_Form_CONFIG.FORM_HEADER_MARGIN_MOVE, UI_Form_CONFIG.FORM_HEADER_MARGIN_MOVE, 1);
GL11.glScalef(UI_Form_CONFIG.FORM_HEADER_BORDER_WIDTH, UI_Form_CONFIG.FORM_HEADER_BORDER_HEIGHT / 2, 0);
drawQuad();
GL11.glPopMatrix();

GL11.glPopMatrix();

GL11.glPopMatrix();[/source]


Problem is that second object ignores second glTranslatef in this case. If i would remove first glPushMatrix and last glPopMatrix, everything would work well, but the actuall form rendering code is quite bigger and i would like to know what am i doing wrong.

Maybe someone has any clues to what am i doing wrong?


Edit:
I call function to draw form in this code

[source lang="java"]
GL11.glPushMatrix();

glMatrixMode(GL_PROJECTION);
GL11.glPushMatrix();

GL11.glLoadIdentity();

glOrtho(0, UTILITY.SCREEN_WIDTH, UTILITY.SCREEN_HEIGHT, 0, 5, -5);

drawForm();

GL11.glPopMatrix();
glMatrixMode(GL_MODELVIEW);

GL11.glPopMatrix();[/source] Edited by Sollum
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1348417298' post='4982952']
Your current matrix mode is GL_PROJECTION when you're drawing and GL only specifies a stack depth of 2 for that (individual implementations may provide more but it's not guaranteed). The amount of pushing and popping you're doing is just overflowing the matrix stack.

You probably also don't want to be calling glScalef and glTranslatef on the projection matrix; these are more commonly used on modelview (the fact that the projection matrix stack is only specified as 2 deep is a pretty good hint that it's not intended to be used this way).
[/quote]

Oh my...

Thanks!

My first thought was that all matrixes have stack of 16, but now that you mention, i didnt notice i am using projection matrix all the time!

Thanks!
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1348417719' post='4982955']
[url="http://www.opengl.org/sdk/docs/man/xhtml/glPushMatrix.xml"]http://www.opengl.or...lPushMatrix.xml[/url] - modelview is specified as 32, the others as 2.
[/quote]

Thanks!

I will think of some fast workaround.

P.S. I am drawing 2d menu onto 3d space, thats why i am using glOrtho, whilst model view matrix is storing last "3d" view

P.P.S. Changed my 2d menu drawing menu routine into
[source lang="java"]
GL11.glPushMatrix();

glMatrixMode(GL_PROJECTION);
GL11.glPushMatrix();

GL11.glLoadIdentity();

glOrtho(0, UTILITY.SCREEN_WIDTH, UTILITY.SCREEN_HEIGHT, 0, 5, -5);
glMatrixMode(GL_MODELVIEW);

drawForm();

glMatrixMode(GL_PROJECTION);
GL11.glPopMatrix();
glMatrixMode(GL_MODELVIEW);

GL11.glPopMatrix();[/source]

Seems to work... for now... Edited by Sollum
0

Share this post


Link to post
Share on other sites
[quote name='Sollum' timestamp='1348418048' post='4982958']
I will think of some fast workaround.
[/quote]

You know you are using deprecated [url="http://www.opengl.org/wiki/Legacy_OpenGL"]legacy OpenGL[/url]?
0

Share this post


Link to post
Share on other sites
[quote name='larspensjo' timestamp='1348423254' post='4982987']
[quote name='Sollum' timestamp='1348418048' post='4982958']
I will think of some fast workaround.
[/quote]

You know you are using deprecated [url="http://www.opengl.org/wiki/Legacy_OpenGL"]legacy OpenGL[/url]?
[/quote]

Yes, i do. Hell was i surprised when i used GL ES 2.0 on Android, its so alien to me (facepalm). They don't even promote view matrixes ._.

At the moment i am trying to make game logic and mechanics work, rather than graphical side. If i will go somewhere near comercial, i will surely consider rewriting graphics "engine". But for now, old opengl is more than enough for my project to work at decent framerate.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0