diff --git a/v3/raycaster.py b/v3/raycaster.py index e4ff94d..ae1740c 100755 --- a/v3/raycaster.py +++ b/v3/raycaster.py @@ -48,8 +48,8 @@ TEXTURES = [ TEXTURE_SIZE = 64 # Raycast cfg -RAYCAST_WIN_WIDTH = 600 -RAYCAST_WIN_HEIGHT = 600 +RAYCAST_WIN_WIDTH = 1000 +RAYCAST_WIN_HEIGHT = 1000 RAYCAST_RENDER_WIDTH = int(RAYCAST_WIN_WIDTH / 4) RAYCAST_RENDER_HEIGHT = int(RAYCAST_WIN_HEIGHT / 4) DOF = 2*MAP_SIZE # Depth Of Field @@ -119,10 +119,10 @@ class Main: self.mapWindow.show() self.mapSurface = self.mapWindow.get_surface() - self.raycastWindow = sdl2.ext.Window("3D View", size=(RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT)) - self.raycastWindow.show() - self.raycastSurface = self.raycastWindow.get_surface() - self.raycast_u32_pixels = ctypes.cast(self.raycastSurface.pixels, ctypes.POINTER(ctypes.c_uint32)) # Raw SDL surface pixel array + self.raycastWindow = sdl2.SDL_CreateWindow(b"3D View", 100, 100, RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT,sdl2.SDL_WINDOW_SHOWN) + self.raycastRenderer = sdl2.SDL_CreateRenderer(self.raycastWindow, -1,sdl2.SDL_RENDERER_ACCELERATED |sdl2.SDL_RENDERER_PRESENTVSYNC) + self.raycastSurface = sdl2.SDL_CreateRGBSurface(0,RAYCAST_WIN_WIDTH,RAYCAST_WIN_HEIGHT,32,0,0,0,0) + self.raycast_u32_pixels = ctypes.cast(self.raycastSurface.contents.pixels, ctypes.POINTER(ctypes.c_uint32)) # Raw SDL surface pixel array # Player self.player_position = {"x": int(MAP_SCALE * PLAYER_SPAWN_POSITION["x"]), "y": int(MAP_SCALE * PLAYER_SPAWN_POSITION["y"]), "r": PLAYER_SPAWN_POSITION["r"]} # r is rotation in radiants @@ -179,7 +179,7 @@ class Main: self.draw() if not MAP_HIDDEN: self.mapWindow.refresh() - self.raycastWindow.refresh() + #self.raycastWindow.refresh() # Calculate FPS frames = frames + 1 @@ -214,8 +214,18 @@ class Main: if not MAP_HIDDEN: self.draw2Dmap() self.drawPlayer() + + + for i in range(0, RAYCAST_WIN_WIDTH * RAYCAST_WIN_HEIGHT): + self.raycast_u32_pixels[i] = (64 << 16) + (64 << 8) + 64 + self.drawRays() + sdl2.SDL_RenderClear(self.raycastRenderer) + raycastTexture = sdl2.SDL_CreateTextureFromSurface(self.raycastRenderer, self.raycastSurface) + sdl2.SDL_RenderCopy(self.raycastRenderer, raycastTexture, None, None) + sdl2.SDL_RenderPresent(self.raycastRenderer) + def drawPlayer(self): # Player in 2D map sdl2.ext.draw.fill(self.mapSurface, sdl2.ext.Color(0,255,0,255), (self.player_position["x"] - 2, self.player_position["y"] - 2, 4, 4)) @@ -239,8 +249,8 @@ class Main: sdl2.ext.draw.fill(self.mapSurface, sdl2.ext.Color(color,color,color,255), (posX, posY, MAP_SCALE - 1, MAP_SCALE - 1)) def drawRays(self): - sdl2.ext.draw.fill(self.raycastSurface, CEILING_COLOR, (0, 0, RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT/2)) # Clears upper raycast screen (draws ceiling) - sdl2.ext.draw.fill(self.raycastSurface, FLOOR_COLOR, (0, RAYCAST_WIN_HEIGHT/2, RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT/2)) # Clears upper raycast screen (draws floor) + #sdl2.ext.draw.fill(self.raycastSurface, CEILING_COLOR, (0, 0, RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT/2)) # Clears upper raycast screen (draws ceiling) + #sdl2.ext.draw.fill(self.raycastSurface, FLOOR_COLOR, (0, RAYCAST_WIN_HEIGHT/2, RAYCAST_WIN_WIDTH, RAYCAST_WIN_HEIGHT/2)) # Clears upper raycast screen (draws floor) # Casts rays for raycasting playerAngle = self.player_position["r"]