Skip to content

Commit

Permalink
Removed the background, added transparency.
Browse files Browse the repository at this point in the history
  • Loading branch information
Echriser committed Apr 14, 2022
1 parent ea33fc7 commit 5f4001f
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
Binary file removed src/assets/bg.jpg
Binary file not shown.
3 changes: 1 addition & 2 deletions src/common.nim
Original file line number Diff line number Diff line change
@@ -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

Expand Down
32 changes: 2 additions & 30 deletions src/core.nim
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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
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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
43 changes: 42 additions & 1 deletion src/vim3.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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()

Expand All @@ -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)

Expand All @@ -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)
Expand All @@ -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()

Expand Down
Binary file added vim3.exe
Binary file not shown.

0 comments on commit 5f4001f

Please sign in to comment.