init
This commit is contained in:
26
flake.lock
generated
Normal file
26
flake.lock
generated
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1763966396,
|
||||
"narHash": "sha256-6eeL1YPcY1MV3DDStIDIdy/zZCDKgHdkCmsrLJFiZf0=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5ae3b07d8d6527c42f17c876e404993199144b6a",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-unstable",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
21
flake.nix
Normal file
21
flake.nix
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
};
|
||||
outputs = {nixpkgs, ...}: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
packages.${system} = {
|
||||
default = pkgs.callPackage ./package.nix {};
|
||||
};
|
||||
devShells.${system} = {
|
||||
default = pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
];
|
||||
shellHook = ''
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
43
package.nix
Normal file
43
package.nix
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
haskellPackages,
|
||||
lib,
|
||||
stdenv,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
ghcExeOptions = "-Wall -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-export-lists -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N";
|
||||
ghcPackages = p: [
|
||||
p.OpenGL
|
||||
p.GLFW-b
|
||||
];
|
||||
in
|
||||
stdenv.mkDerivation {
|
||||
pname = "haskengl";
|
||||
version = "0.1.0";
|
||||
src = ./src;
|
||||
nativeBuildInputs = [
|
||||
(haskellPackages.ghcWithPackages ghcPackages)
|
||||
pkgs.libGL
|
||||
pkgs.libGLU
|
||||
];
|
||||
buildInputs = [
|
||||
pkgs.libGL
|
||||
pkgs.libGLU
|
||||
];
|
||||
configurePhase = ''
|
||||
'';
|
||||
buildPhase = ''
|
||||
ghc ${ghcExeOptions} ./Main.hs -o ./Main
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ./Main $out/bin/haskengl
|
||||
'';
|
||||
|
||||
meta = {
|
||||
homepage = "https://mtgmonkey.net";
|
||||
license = lib.licenses.wtfpl;
|
||||
mainProgram = "haskengl";
|
||||
platforms = ["x86_64-linux"];
|
||||
};
|
||||
}
|
||||
77
src/Main.hs
Normal file
77
src/Main.hs
Normal file
@@ -0,0 +1,77 @@
|
||||
module Main (main) where
|
||||
|
||||
-- IMPORTS --
|
||||
|
||||
import Graphics.Rendering.OpenGL as GL
|
||||
import Graphics.UI.GLFW as GLFW
|
||||
import Control.Monad (forever)
|
||||
import System.Exit (exitSuccess)
|
||||
|
||||
-- MAIN --
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
putStrLn "haskengl 2025 Andromeda; WTFPL"
|
||||
window <- openWindow "window :)"
|
||||
onPaint window
|
||||
closeWindow window
|
||||
return ()
|
||||
|
||||
-- EVENTS --
|
||||
|
||||
keyPressed :: GLFW.KeyCallback
|
||||
keyPressed window GLFW.Key'Escape _ GLFW.KeyState'Pressed _ = shutdownWindow window
|
||||
keyPressed _ _ _ _ _ = return ()
|
||||
|
||||
-- PAINT --
|
||||
|
||||
onPaint :: GLFW.Window -> IO ()
|
||||
onPaint window =
|
||||
do
|
||||
GL.clearColor $= Color4 1 0 1 1
|
||||
GL.clear [ColorBuffer]
|
||||
GLFW.swapBuffers window
|
||||
forever $ do
|
||||
GLFW.pollEvents
|
||||
onPaint window
|
||||
|
||||
-- WINDOW --
|
||||
|
||||
openWindow :: String -> IO GLFW.Window
|
||||
openWindow
|
||||
title
|
||||
= do
|
||||
GLFW.init
|
||||
GLFW.defaultWindowHints
|
||||
GLFW.windowHint (GLFW.WindowHint'ContextVersionMajor 4)
|
||||
GLFW.windowHint (GLFW.WindowHint'ContextVersionMinor 5)
|
||||
GLFW.windowHint (GLFW.WindowHint'OpenGLProfile GLFW.OpenGLProfile'Core)
|
||||
monitor <- GLFW.getPrimaryMonitor
|
||||
Just window <- GLFW.createWindow 256 256 title monitor Nothing -- get an error n ur cooked. TODO graceful failure here
|
||||
GLFW.makeContextCurrent (Just window)
|
||||
GLFW.maximizeWindow window
|
||||
GLFW.setWindowCloseCallback window (Just shutdownWindow)
|
||||
GLFW.setWindowSizeCallback window (Just resizeWindow)
|
||||
GLFW.setKeyCallback window (Just keyPressed)
|
||||
return window
|
||||
|
||||
shutdownWindow :: GLFW.WindowCloseCallback
|
||||
shutdownWindow window =
|
||||
do
|
||||
closeWindow window
|
||||
_ <- exitSuccess
|
||||
return ()
|
||||
|
||||
resizeWindow :: GLFW.WindowSizeCallback
|
||||
resizeWindow _ w h =
|
||||
do
|
||||
GL.viewport $= (GL.Position 0 0, GL.Size (fromIntegral w) (fromIntegral h))
|
||||
GL.matrixMode $= GL.Projection
|
||||
GL.loadIdentity
|
||||
GL.ortho2D 0 (realToFrac w) (realToFrac h) 0
|
||||
|
||||
closeWindow :: GLFW.Window -> IO ()
|
||||
closeWindow window =
|
||||
do
|
||||
GLFW.destroyWindow window
|
||||
GLFW.terminate
|
||||
Reference in New Issue
Block a user