diff --git a/src/assets/bg.jpg b/src/assets/bg.jpg deleted file mode 100644 index e21a585..0000000 Binary files a/src/assets/bg.jpg and /dev/null differ diff --git a/src/common.nim b/src/common.nim index f6d8de3..9e6666c 100644 --- a/src/common.nim +++ b/src/common.nim @@ -1,7 +1,6 @@ -import paranim/gl, paranim/gl/uniforms, paranim/gl/attributes +import paranim/gl, paranim/gl/uniforms import nimgl/opengl import glm -from sequtils import map from std/math import nil import paranim/math as pmath diff --git a/src/core.nim b/src/core.nim index e48feeb..8a00c5a 100644 --- a/src/core.nim +++ b/src/core.nim @@ -1,5 +1,5 @@ import nimgl/opengl -import paranim/gl, paranim/gl/uniforms, paranim/gl/attributes, paranim/gl/entities +import paranim/gl, paranim/gl/uniforms, paranim/gl/attributes import paranim/math as pmath import common, data from bitops import bitor @@ -7,7 +7,6 @@ from std/math import nil import glm from paravim/core as paravim_core import nil from paravim import nil -import stb_image/read as stbi from pararules import nil type @@ -36,13 +35,8 @@ proc initThreeDMetaTextureEntity(posData: openArray[GLfloat], texcoordData: open var entity: ThreeDMetaTextureEntity - imageEntity: ImageEntity rx = degToRad(180f) ry = degToRad(40f) - imageWidth: int - imageHeight: int - -const image = staticRead("assets/bg.jpg") proc init*(game: var Game) = doAssert glInit() @@ -79,33 +73,11 @@ proc init*(game: var Game) = entity = compile(game, initThreeDMetaTextureEntity(cube, cubeTexcoords, outerImage)) - var - channels: int - data: seq[uint8] - data = stbi.loadFromMemory(cast[seq[uint8]](image), imageWidth, imageHeight, channels, stbi.RGBA) - imageEntity = compile(game, initImageEntity(data, imageWidth, imageHeight)) - proc tick*(game: Game) = - glClearColor(1f, 1f, 1f, 1f) + glClearColor(0.0f, 0.0f, 0.0f, 0.0f) glClear(GLbitfield(bitor(GL_COLOR_BUFFER_BIT.ord, GL_DEPTH_BUFFER_BIT.ord))) glViewport(0, 0, GLsizei(game.frameWidth), GLsizei(game.frameHeight)) - block: - glDisable(GL_CULL_FACE) - let - frameRatio = game.frameWidth.float / game.frameHeight.float - imageRatio = imageWidth.float / imageHeight.float - (width, height) = - if frameRatio > imageRatio: - (game.frameWidth.float, game.frameWidth.float * (imageHeight.float / imageWidth.float)) - else: - (game.frameHeight.float * imageRatio, game.frameHeight.float) - var e = imageEntity - e.project(float(game.frameWidth), float(game.frameHeight)) - e.translate(0f, 0f) - e.scale(width, height) - render(game, e) - var camera = mat4f(1) camera.translate(0f, 0f, 2f) camera.lookAt(vec3(0f, 0f, 0f), vec3(0f, 1f, 0f)) diff --git a/src/vim3.nim b/src/vim3.nim index 8fcc591..f1dab9b 100644 --- a/src/vim3.nim +++ b/src/vim3.nim @@ -6,6 +6,19 @@ from os import nil var game = Game() +var + isDragging: bool = false + mousex: float + mousey: float + mouseposx: int32 + mouseposy: int32 + windowx: int32 + windowy: int32 + init_mx: int32 + init_my: int32 + relative_mx: int32 + relative_my:int32 + proc keyCallback(window: GLFWWindow, key: int32, scancode: int32, action: int32, mods: int32) {.cdecl.} = paravim.keyCallback(window, key, scancode, action, mods) @@ -16,6 +29,25 @@ proc frameSizeCallback(window: GLFWWindow, width: int32, height: int32) {.cdecl. game.frameWidth = width game.frameHeight = height +proc mouseClickCallback(window: GLFWWindow, button: int32, action: int32, mods: int32) {.cdecl.} = + window.getCursorPos(mousex.addr, mousey.addr) + if button == 0 and action == GLFWPress: + isDragging = true + mouseposx = mousex.int32 + mouseposy = mousey.int32 + if init_mx == 0 and init_my == 0: + init_mx = mouseposx + init_my = mouseposy + if button == 0 and action == GLFWRelease: + isDragging = false + init_mx = 0 + init_my = 0 + +proc mouseMoveCallback(window: GLFWWindow, xpos: float, ypos: float) {.cdecl.} = + if isDragging: + relative_mx = xpos.int32 + relative_my = ypos.int32 + when isMainModule: doAssert glfwInit() @@ -24,8 +56,10 @@ when isMainModule: glfwWindowHint(GLFWOpenglForwardCompat, GLFW_TRUE) # Used for Mac glfwWindowHint(GLFWOpenglProfile, GLFW_OPENGL_CORE_PROFILE) glfwWindowHint(GLFWResizable, GLFW_TRUE) + glfwWindowHint(GLFWDecorated, GLFWFalse) + glfwWindowHint(GLFWTransparentFramebuffer, GLFWTrue) - let w: GLFWWindow = glfwCreateWindow(1024, 768, "VimĀ³ - You can begin by typing `:e path/to/myfile.txt`") + let w: GLFWWindow = glfwCreateWindow(768, 768, "VimĀ³ - You can begin by typing `:e path/to/myfile.txt`") if w == nil: quit(-1) @@ -35,6 +69,8 @@ when isMainModule: discard w.setKeyCallback(keyCallback) discard w.setCharCallback(charCallback) discard w.setFramebufferSizeCallback(frameSizeCallback) + discard w.setMouseButtonCallback(mouseClickCallback) + discard w.setCursorPosCallback(mouseMoveCallback) var width, height: int32 w.getFramebufferSize(width.addr, height.addr) @@ -51,6 +87,11 @@ when isMainModule: game.deltaTime = ts - game.totalTime game.totalTime = ts core.tick(game) + + if isDragging: + w.getWindowPos(windowx.addr, windowy.addr) + w.setWindowPos(windowx+relative_mx-init_mx, windowy+relative_my-init_my) + w.swapBuffers() glfwPollEvents() diff --git a/vim3.exe b/vim3.exe new file mode 100644 index 0000000..4300935 Binary files /dev/null and b/vim3.exe differ