On Tue, Dec 9, 2008 at 3:58 PM, Paul <[EMAIL PROTECTED]> wrote: > This change to the on_resize function will enforce a 4:3 viewport in the > Pong example, thus allowing user resizing of the window without distortion: > > def on_resize(width, height): > > # prevent division by zero > if width == 0: width = 1 > if height == 0: height = 1 > > # enforce 4:3 aspect ratio by reducing the excess dimension > if 1.0 * width / height > 4.0 / 3: > width = int(height * 4.0 / 3) > elif 1.0 * width / height < 4.0 / 3: > height = int(width * 3.0 / 4) > > # center viewport in window > glViewport((window.width - width) // 2, (window.height - height) // 2, > width, height)
Nice work! I was thinking of adapting the drawing code to accomplish the same effect, but that is far simpler. Mind if I include that change in the updated version next week? - Tristam > > > On Tue, Dec 9, 2008 at 9:18 AM, Tristam MacDonald <[EMAIL PROTECTED]>wrote: > >> >> >> On Tue, Dec 9, 2008 at 12:12 PM, Paul <[EMAIL PROTECTED]> wrote: >> >>> Also, I noticed there's a function to handle window resizing, but the >>> window is not resizable. Adding the window attribute "resizable=True" makes >>> it work as expected. >>> >> >> I was actually just using the window resize callback to intercept the >> initial window size and setup the custom projection matrix. The resize >> handler is called not only when the window is resized, but also when it is >> made visible (at least the first time). >> >> This allows one to change the resolution of the created window by changing >> only the parameters of the window creation, rather than having to change the >> dimensions in multiple places. >> >> Allowing the user to resize the window is a bit of a mixed bag with a >> fixed size playing field, because you then need to enforce or compensate to >> match the 4x3 aspect ratio on each resize. >> >> >> On Tue, Dec 9, 2008 at 3:56 AM, Tristam MacDonald <[EMAIL PROTECTED]>wrote: >>> >>>> On Tue, Dec 9, 2008 at 12:28 AM, vaibhav <[EMAIL PROTECTED]>wrote: >>>> >>>>> >>>>> hi Tristam, >>>>> this is a great example. i better understand states now. i found one >>>>> typo in the last line of main update function, though i don't think >>>>> that 'else' condition is ever met. >>>>> >>>>> # update callback >>>>> def update(dt): >>>>> # update the topmost state, if we have any >>>>> if len(states): >>>>> states[-1].update(dt) >>>>> # otherwise quit >>>>> else: >>>>> app.exit() >>>>> >>>>> the last line should be >>>>> pyglet.app.exit() >>>>> >>>> >>>> Thanks, I have corrected that in the source. You are correct that it is >>>> never reached in the current app, but it is intended to make sure that the >>>> application will quit if the last state is popped (rather than get stuck in >>>> an infinite loop). >>>> >>>> - Tristam >>>> >>>> >>>>> thanks for the example >>>>> vaibhav >>>>> >>>>> On Dec 8, 2:48 pm, "Tristam MacDonald" <[EMAIL PROTECTED]> wrote: >>>>> > On Mon, Dec 8, 2008 at 5:43 PM, Alex Holkner <[EMAIL PROTECTED]> >>>>> wrote: >>>>> > >>>>> > > On 12/9/08, Tristam MacDonald <[EMAIL PROTECTED]> wrote: >>>>> > > > In case anyone is interested, I wrote a simple pong clone using >>>>> Pyglet. >>>>> > >>>>> > > > The source is fairly heavily commented, and I attempted to use >>>>> best >>>>> > > > practices throughout, in the hopes that it would be of use to >>>>> anyone >>>>> > > > learning Pyglet. >>>>> > >>>>> > > > Comments and suggestions are welcome, and you can find it here: >>>>> > > >http://swiftcoder.wordpress.com/2008/12/08/pong/ >>>>> > >>>>> > > This is a great example, and just needs sound effects (and for the >>>>> CPU >>>>> > > player not to cheat!). If you relicense the code under a BSD >>>>> license >>>>> > > I can include it in the pyglet examples/ distribution. >>>>> > >>>>> > > Cheers >>>>> > > Alex. >>>>> > >>>>> > No problem, I would be glad to contribute to the distribution. I plan >>>>> to add >>>>> > some 'artificial stupidity' to the CPU player in the next few days, >>>>> but feel >>>>> > free to modify the code as you see fit, and the BSD license is fine. >>>>> > >>>>> > I intend to produce a series of these simple games, partly as the >>>>> start of >>>>> > my game development portfolio, but also to help out anyone who needs >>>>> it - I >>>>> > will update you all when the next is released. >>>>> > >>>>> > - Tristam >>>>> >>>>> >>>> >>>> >>>> >>> >>> >>> >> >> >> > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en -~----------~----~----~----~------~----~------~--~---
