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

glm.vec2 & glm.vec3 do not work, from both my own code and complete copy paste from source code. #2

Open
echoless3484 opened this issue Jul 1, 2023 · 4 comments

Comments

@echoless3484
Copy link

echoless3484 commented Jul 1, 2023

Error

"C:\Users\#\Game Development\Hellow3DWorld\venv\Scripts\python.exe" "C:\Users\#\Game Development\Hellow3DWorld\h3Dw\main.py" 
Traceback (most recent call last):
  File "C:\Users\echol\Game Development\Hellow3DWorld\h3Dw\main.py", line 1, in <module>
    from settings import *
  File "C:\Users\echol\Game Development\Hellow3DWorld\h3Dw\settings.py", line 7, in <module>
    WIN_RES = glm.vec2(1600, 900)
              ^^^^^^^^
AttributeError: module 'glm' has no attribute 'vec2'

Process finished with exit code 1

settings.py:

from numba import njit
import numpy as np
import glm
import math

# resolution
WIN_RES = glm.vec2(1600, 900)

# colors
BG_COLOR = glm.vec3(0.1, 0.16, 0.25)

main.py:

from settings import *
import moderngl as mgl
import pygame as pg
import sys


class VoxelEngine:
    def __init__(self):
        pg.init()
        pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
        pg.display.gl_set_attribute(pg.GL_CONTEXT_MINOR_VERSION, 3)
        pg.display.gl_set_attribute(pg.GL_CONTEXT_PROFILE_MASK, pg.GL_CONTEXT_PROFILE_CORE)
        pg.display.gl_set_attribute(pg.GL_DEPTH_SIZE, 24)

        pg.display.set_mode(WIN_RES, flags=pg.OPENGL | pg.DOUBLEBUF)
        self.ctx = mgl.create_context()

        self.ctx.enable(flags=mgl.DEPTH_TEST | mgl.CULL_FACE | mgl.BLEND)
        self.ctx.gc_mode = 'auto'

        self.clock = pg.time.Clock()
        self.delta_time = 0
        self.time = 0

        self.is_running = True

    def update(self):
        self.delta_time = self.clock.tick()
        self.time = pg.time.get_ticks() * 0.001
        pg.display.set_caption(f'{self.clock.get_fps() :.0f}')

    def render(self):
        self.ctx.clear(color=BG_COLOR)
        pg.display.flip()

    def handle_events(self):
        for event in pg.event.get():
            if event.type == pg.QUIT or (event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE):
                self.is_running = False

    def run(self):
        while self.is_running:
            self.handle_events()
            self.update()
            self.render()
        pg.quit()
        sys.exit()


if __name__ == '__main__':
    app = VoxelEngine()
    app.run()
@sudokit
Copy link

sudokit commented Jul 18, 2023

try:
pip uninstall PyGLM glm and then pip install PyGLM

@Wojtek9388
Copy link

try: pip uninstall PyGLM glm and then pip install PyGLM

that work for fixing the settings now im getting
Traceback (most recent call last):
File "c:\Users\a\Desktop\Voxel Engine\main.py", line 48, in
app = Voxel_Engine()
^^^^^^^^^^^^^^
File "c:\Users\a\Desktop\Voxel Engine\main.py", line 9, in init
pg.display.gl_set_attribute(pg.GL_CONTEXT_MAJOR_VERSION, 3)
pygame.error: video system not initialized

@sudokit
Copy link

sudokit commented Nov 6, 2023

Quiiick tippp: Google stuff :p

but you most likely forgot to call pygame.init() somewhere

(sorry a bit late)

@JustAnEric
Copy link

JustAnEric commented Nov 26, 2023

@Wojtek9388 You need to initialize your Pygame instance before integrating with OpenGL graphics. This tutorial imports pygame as pg, so do this in your main.py file:

...
import pygame as pg
...
class VoxelEngine:
    def __init__(self):
        pg.init()
...

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

4 participants