Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layer size is a quarter of the window size on Mac #303

Open
yousiku opened this issue Nov 19, 2017 · 12 comments
Open

layer size is a quarter of the window size on Mac #303

yousiku opened this issue Nov 19, 2017 · 12 comments

Comments

@yousiku
Copy link

yousiku commented Nov 19, 2017


1511099214077

My enviroment:
macOS 10.12.6
python 3.6.3
cocos2d 0.6.5

it's the same result running any of the samples on my computer.
When I print director.get_window_size() it returns (640, 480)
but when I set label.postion = 320, 240, it's obviously not in the center of window, and the layer's size is always a quarter of the window. why?

@ccanepa
Copy link
Contributor

ccanepa commented Nov 19, 2017

Hello, yousiku

Is that image from a demo_grid_effects.py without any changes in the code ?

That mac has a retina display ?

Can you try this pure pyglet script? It should show the string '---o---' with the 'o' at the screen center.
If it shows not at center the problem comes from pyglet, and you should open an issue in their bug tracker

"""shows the string '---o---', screen center should be on the 'o'
"""

from pyglet.gl import *
import pyglet
from pyglet.window import key


window = pyglet.window.Window(640, 480)

@window.event
def on_key_press(symbol, modifiers):
    if symbol == key.ESCAPE:
        window.has_exit = True

@window.event
def on_draw():
    window.clear()
    label.draw()

def update(dt):
    pass
pyglet.clock.schedule_interval(update, 1/30.)

label = pyglet.text.Label('---o---',
                          font_size=14,
                          x=window.width // 2, y=window.height // 2, 
                          anchor_x='center')

if __name__ == '__main__':
    pyglet.app.run()

@yousiku
Copy link
Author

yousiku commented Nov 20, 2017

@ccanepa
I tried this script and the 'O' is at the center.
All the images was without changes, the Mac has Retina display, is that related to the display?
I guess there was something wrong when added the Layer to the Scene, or it created a window with width and height double then the normal.

@ccanepa
Copy link
Contributor

ccanepa commented Nov 20, 2017

To support the high resolution in Retina displays sometimes a software layer do a "behind your back" "double the widths and heights", so it may be related.

But if pyglet displays ok, then we can make cocos to perform ok.

I don't have access to a mac so I need to collect some info.
Could you insert, in the pyglet script above, the line
print(window.width, window.height)
after the line
window = pyglet.window.Window(640, 480)
run from a console and report what numbers were printed?

@ccanepa
Copy link
Contributor

ccanepa commented Nov 20, 2017

Also, which pyglet version are you running?
I found some references that suggest pyglet changed behavior for retina displays in v1.3
https://bitbucket.org/pyglet/pyglet/issues/45/retina-display-scaling-on-os-x
https://groups.google.com/forum/#!topic/pyglet-users/M6mkxdg0EJc

@yousiku
Copy link
Author

yousiku commented Nov 21, 2017

@ccanepa

The line prints 640 480, and the pyglet version is 1.3.0

It seems that the problem is the Retina display, everything worked perfectly after applied this patch file from https://bitbucket.org/pyglet/pyglet/issues/45/retina-display-scaling-on-os-x

Thank you so much!

@fpierfed
Copy link

fpierfed commented Feb 22, 2018

Hello,

I am having the same issue on Macs with HiDPI screen resolutions (not just macbooks).

One solution is to detect HiDPI resolutions and increase the window size values accordingly. This can be done in Director.scaled_resize_window and Director.unscaled_resize_window as per the patch attached below.

Bear in mind however that I do not know enough about cocos or pyglet to know if this is a terribly inefficient way to go about it or not...

I should add that this change requires pyglet.window.Window.get_viewport_size() which was introduced only fairly recently.

hidpi.patch.txt

@a69e
Copy link

a69e commented Dec 29, 2018

Thanks for fixing this! I've met the same problem today, and after the path everything's cool now. 👍
BTW, @ccanepa could you possibly merge this patch so that no one needs to manually patch no more?

@ghost
Copy link

ghost commented Mar 17, 2021

The patch provided above seems to have a bug which causes a crash when you resize the window. I have a fix that could be merged and works even when resizing the window. I've posted it here as PR #340 for review and have some extra pairs of eyes looking at it.

@ghost
Copy link

ghost commented Jul 15, 2021

I fixed the issue in my original PR that was preventing the unit tests from completing. This is still probably mostly relevant for macOS but at least other architectures that provide get_viewport_size() on pyglet.Window should work too. New PR is #346

@MTurandot
Copy link

@ccanepa

The line prints 640 480, and the pyglet version is 1.3.0

It seems that the problem is the Retina display, everything worked perfectly after applied this patch file from https://bitbucket.org/pyglet/pyglet/issues/45/retina-display-scaling-on-os-x

Thank you so much!

I almost have the same problem but the link you listed above is not available now.
Could you please tell me how to solve it?

@shayneoneill
Copy link

Whats the current fix for this?

@ccanepa
Copy link
Contributor

ccanepa commented Nov 18, 2023

The patch by Didier Malenfant is on master.

Release is lagging due to python 3.12 compatibility issues; one has been fixed, pyglet/pyglet#964 , theres an import one in cocos that should be not hard but I'm missing the time to look at..

@los-cocos los-cocos deleted a comment from LeoLee98 Nov 18, 2023
@los-cocos los-cocos deleted a comment from LeoLee98 Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants