Reputation: 13
I'm working on a Minecraft clone (mainly working on improvements over obiwac's series) using Pyglet and GL (pyglet.gl), and I'm trying to add a basic HUD. The HUD I've made renders fine, until the window is scaled, where it either goes offscreen or gets stretched out (stretching usually happens when the window is scaled horizontally, while it goes offscreen when scaled vertically)
Here's a video of the issue occuring: https://youtu.be/p8Zz8pnF_iE # if this didn't embed sry
Here's some code related to the issue:
class F3Display(pyglet.window.FPSDisplay):
def __init__(self, window, color=(255, 255, 255, 255), samples=240):
super().__init__(window, color, samples)
self.window = window
self.label.width = window.width // 3
self.label.font_name = "Minecraft"
self.label.font_size = window.height // 60
self.label.multiline = True
self.label.x = 10
self.label.y = window.height - 10
def update(self):
t = self._time()
delta = t - self._last_time
self._elapsed += delta
self._delta_times.append(delta)
self._last_time = t
if self._elapsed >= self.update_period:
self._elapsed = 0
self.label.text = f"""{1 / self._mean(self._delta_times):.0f} FPS
Position: (X: {round(self.window.player.position[0], 3)} / Y: {round(self.window.player.position[1], 3)} / Z: {round(self.window.player.position[2], 3)})
OpenGL Version: {self.window.gl_version[0]}.{self.window.gl_version[1]}
Python Version: {sys.version}
"""
MCPyWindow.on_resize:
def on_resize(self, width, height):
print(f"Resized to {width}x{height}")
gl.glViewport(0, 0, width, height)
print(f"Crosshair should be at {width // 2}, {height // 2}")
print(f"F3Display should be at {10}, {height - 30}, with width {width // 2.5} and font size {max(10, height // 60)}")
self.player.view_width = width
self.player.view_height = height
self.f3.label.x = 10
self.f3.label.y = height - 30
self.f3.label.font_size = max(10, height // 60)
self.f3.label.width = width // 3
self.crosshair.x = width // 2
self.crosshair.y = height // 2
If you need any more details, please ask in the comments.
Until this is solved, it'll be difficult to continue this project.
Thanks, xavvvv
Upvotes: 0
Views: 28