• 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.

Archived

This topic is now archived and is closed to further replies.

GekkoCube

glFrustum and glPerspective difference?

7 posts in this topic

what is the difference? i tried both, not at the same time, and opengl appears to work. is glFrustum basically a more advanced viewing system over glPerspective?
0

Share this post


Link to post
Share on other sites
i had the same question a few weeks ago...
gluPerspective calls glFrustum...
i made my own version of this function and some others to
eliminate dependency on the GLU library and shave a few kilobytes
off the EXE size... although i don''t remember exactly how i wrote
it (i''ve replaced it with a customized version), this should
work:

const double pi180 = 0.017453292519943295769236907684886;
// pi/180

// replacement for gluPerspective
void setPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar){
GLdouble top, bottom, left, right;
top = zNear * tan(pi180*fovy/2);
bottom = -top;
right = aspect*top;
left = -right;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left, right, bottom, top, zNear, zFar);
glMatrixMode(GL_MODELVIEW);
}

note: this function isn''t exactly like gluPerspective... the difference is the call the glLoadIdentity, and the glMatrixMode calls which i put there for convenience

this may or may not answer your question... but knowing how gluPerspective works enables you to use the more powerful glFrustum to customize the camera''s view.
0

Share this post


Link to post
Share on other sites
I''d be very surprised if gluPerspective calls glFrustrum. That would create unnessicary overhead. Both functions perform the exact same operation, which is to generate a 4x4 perspective matrix. The only difference is in the values you pass them. glFrustrum requires that you specify the values for the upper, lower, left, and right clipping planes, while gluPerspective derives these values from the fov angle and the aspect ratio. It''s one of the simplest uses of matrix math there is. You could easily build your own function that incorporates the functionality of both, or any other system that you may prefer, without relying on either of them.

0

Share this post


Link to post
Share on other sites
quote:
Original post by Nemesis2k2
I''d be very surprised if gluPerspective calls glFrustrum. That would create unnessicary overhead.


overhead that probably nobody cares about because youre not going to call this function a million times per second. i dont know about glu, but for gl nobody is telling you how your implementation has to look like. you can always look at the mesa source to see how they are doing things.

0

Share this post


Link to post
Share on other sites
quote:
Original post by Nemesis2k2
I'd be very surprised if gluPerspective calls glFrustrum.


I agree with Trienco. I would be very surprised if gluPerspective does not call glFrustrum. "Both functions perform the exact same operation" is precisely the reason. No sense in duplicating code. Here's how I would implement gluPerspective:
void gluPerspective( GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far )
{
GLdouble half_height = near * tan( fovy * 0.5 * TWOPI_OVER_360 );
GLdouble half_width = half_height * aspect;

glFrustum( -half_width, half_width, -half_height, half_height, near, far );
}
The only "unnecessary" overhead is the glFrustum call overhead and two negate operations. Who cares??? It is better than unnecessary duplication of code.

[edited by - JohnBolton on September 16, 2003 8:11:23 PM]
0

Share this post


Link to post
Share on other sites
I agree that the overhead is nothing, but still, it's not duplication of code. If you had a decent matrix class, You could implement glFrustrum in one line of code. I'm dead serious. One line. All the examples you've posted are doing is putting the values that were passed to gluPerspective in the form that glFrustrum wants them. That's pointless, especially when you can implement gluPerspective doing less operations than are done in glFrustrum.



[edited by - Nemesis2k2 on September 16, 2003 10:33:37 PM]
0

Share this post


Link to post
Share on other sites
guess i can't disagree there. i'm setting up the "view" matrix from my "camera matrix" by doing the inversion myself. not because its crucial to optimize, simply because i dont like converting the vectors to something glulookat likes and have it reverse the conversion, doing unnecessary cross products and then invert. but here the frustrating part is that lookat internally builds exactly the matrix i already have before inverting it.

but boltons code just brought to my attention, that i shouldnt use perspective in my camera class, as it's using width/2 and height/2 anyway.

though still: there are no rules how an implementation of gluperspective and glfrustum should look like. just what goes in and what comes out.

just had a look and for a typical setup it can be simplified a little:

yFac = tanf(FOV * 3.14f/360);
xFac = yFac*Aspect;
glMatrixMode(GL_PROJECTION);
float PMtr[16]={1/xFac, 0, 0, 0,
0, 1/yFac, 0, 0,
0, 0, -(far+near)/(far-near), -1,
0, 0, -(2*far*near)/(far-near), 0};
glLoadMatrixf(PMtr);
glMatrixMode(GL_MODELVIEW);


(2*near)/(top-bottom):
top=near*tan(..), bottom=-near*tan(..)
extracting near leaves 2/(top-bottom)=2/(2*top)=1/top.
term simplified and calculating yFac for 1 instead of near.

having a nice symmetry the terms right+left and top+bottom evaluate to 0, removing the terms at (3,1) and (3,2).

guess it would really be wasteful to call the much more flexible glfrustum.. but i still dont think anybody cares ,-)

[edited by - Trienco on September 17, 2003 7:09:27 AM]
0

Share this post


Link to post
Share on other sites