moooaaarrr work on triangles ... still nothing
This commit is contained in:
parent
a2c1effb48
commit
7db4bff2e4
@ -25,5 +25,6 @@ executable Pioneers
|
|||||||
pretty >=1.1,
|
pretty >=1.1,
|
||||||
transformers >=0.3.0 && <0.4,
|
transformers >=0.3.0 && <0.4,
|
||||||
mtl >=2.1.2,
|
mtl >=2.1.2,
|
||||||
stm >=2.4.2
|
stm >=2.4.2,
|
||||||
|
vector >=0.10.9 && <0.11
|
||||||
|
|
||||||
|
@ -3,11 +3,10 @@
|
|||||||
//color from earlier stages
|
//color from earlier stages
|
||||||
smooth in vec4 fg_SmoothColor;
|
smooth in vec4 fg_SmoothColor;
|
||||||
|
|
||||||
//color of pixel
|
|
||||||
out vec4 fg_FragColor;
|
out vec4 fg_FragColor;
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
//copy-shader
|
//copy-shader
|
||||||
fg_FragColor = fg_SmoothColor;
|
fg_FragColor = vec4(1,0,0,1) + 0.01* fg_SmoothColor;
|
||||||
}
|
}
|
@ -9,12 +9,12 @@ in vec3 fg_VertexIn;
|
|||||||
in vec3 fg_Normal;
|
in vec3 fg_Normal;
|
||||||
|
|
||||||
//output-data for later stages
|
//output-data for later stages
|
||||||
smooth out vec4 fg_SmoothColor;
|
out vec4 fg_SmoothColor;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
//transform vec3 into vec4, setting w to 1
|
//transform vec3 into vec4, setting w to 1
|
||||||
vec4 fg_Vertex = vec4(fg_VertexIn, 1.0);
|
vec4 fg_Vertex = vec4(fg_VertexIn.x, fg_VertexIn.y+0.1, fg_VertexIn.z, 1.0);
|
||||||
fg_SmoothColor = fg_Color + 0.001* fg_Normal.xyzx;
|
fg_SmoothColor = fg_Color + 0.001* fg_Normal.xyzx;
|
||||||
gl_Position = fg_ProjectionMatrix * fg_Vertex;
|
gl_Position = fg_ProjectionMatrix * fg_Vertex;
|
||||||
}
|
}
|
34
src/Main.hs
34
src/Main.hs
@ -10,12 +10,14 @@ import Data.List (intercalate)
|
|||||||
import Data.Maybe (catMaybes)
|
import Data.Maybe (catMaybes)
|
||||||
import Text.PrettyPrint
|
import Text.PrettyPrint
|
||||||
|
|
||||||
import qualified Graphics.Rendering.OpenGL.GL as GL
|
import qualified Graphics.Rendering.OpenGL.GL as GL
|
||||||
import qualified Graphics.UI.GLFW as GLFW
|
import qualified Graphics.Rendering.OpenGL.Raw.Core31 as GLRaw
|
||||||
|
import qualified Graphics.UI.GLFW as GLFW
|
||||||
|
import qualified Data.Vector.Storable as V
|
||||||
|
|
||||||
import Map.Map
|
import Map.Map
|
||||||
import Render.Render (initShader)
|
import Render.Render (initShader)
|
||||||
import Render.Misc (up, lookAtUniformMatrix4fv, createFrustum)
|
import Render.Misc (up, lookAtUniformMatrix4fv, createFrustum, checkError)
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -385,13 +387,37 @@ draw = do
|
|||||||
map' = stateMap state
|
map' = stateMap state
|
||||||
frust = stateFrustum state
|
frust = stateFrustum state
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
lookAtUniformMatrix4fv (0.0,0.0,0.0) (0, 15, 0) up frust proj 1
|
GLRaw.glClearDepth 1.0
|
||||||
|
GLRaw.glDisable GLRaw.gl_CULL_FACE
|
||||||
|
--lookAtUniformMatrix4fv (0.0,0.0,0.0) (0, 15, 0) up frust proj 1
|
||||||
|
|
||||||
|
-------------
|
||||||
|
|
||||||
|
let fov = 90
|
||||||
|
s = recip (tan $ fov * 0.5 * pi / 180)
|
||||||
|
f = 1000
|
||||||
|
n = 1
|
||||||
|
|
||||||
|
let perspective = V.fromList [ s, 0, 0, 0
|
||||||
|
, 0, s, 0, 0
|
||||||
|
, 0, 0, -(f/(f - n)), -1
|
||||||
|
, 0, 0, -((f*n)/(f-n)), 0
|
||||||
|
]
|
||||||
|
|
||||||
|
V.unsafeWith perspective $ \ptr -> GLRaw.glUniformMatrix4fv proj 1 0 ptr
|
||||||
|
|
||||||
|
---------------
|
||||||
|
|
||||||
GL.bindBuffer GL.ArrayBuffer GL.$= Just map'
|
GL.bindBuffer GL.ArrayBuffer GL.$= Just map'
|
||||||
GL.vertexAttribPointer ci GL.$= fgColorIndex
|
GL.vertexAttribPointer ci GL.$= fgColorIndex
|
||||||
|
GL.vertexAttribArray ci GL.$= GL.Enabled
|
||||||
GL.vertexAttribPointer ni GL.$= fgNormalIndex
|
GL.vertexAttribPointer ni GL.$= fgNormalIndex
|
||||||
|
GL.vertexAttribArray ni GL.$= GL.Enabled
|
||||||
GL.vertexAttribPointer vi GL.$= fgVertexIndex
|
GL.vertexAttribPointer vi GL.$= fgVertexIndex
|
||||||
|
GL.vertexAttribArray vi GL.$= GL.Enabled
|
||||||
|
|
||||||
GL.drawArrays GL.Triangles 0 numVert
|
GL.drawArrays GL.Triangles 0 numVert
|
||||||
|
checkError "draw"
|
||||||
|
|
||||||
getCursorKeyDirections :: GLFW.Window -> IO (Double, Double)
|
getCursorKeyDirections :: GLFW.Window -> IO (Double, Double)
|
||||||
getCursorKeyDirections win = do
|
getCursorKeyDirections win = do
|
||||||
|
@ -80,7 +80,9 @@ getMapBufferObject = do
|
|||||||
bo <- genObjectName -- create a new buffer
|
bo <- genObjectName -- create a new buffer
|
||||||
bindBuffer ArrayBuffer $= Just bo -- bind buffer
|
bindBuffer ArrayBuffer $= Just bo -- bind buffer
|
||||||
withArray map' $ \buffer ->
|
withArray map' $ \buffer ->
|
||||||
bufferData ArrayBuffer $= (fromIntegral (sizeOf(P.head map')), buffer, StaticDraw)
|
bufferData ArrayBuffer $= (fromIntegral $ sizeOf (0 :: Float)*P.length map',
|
||||||
|
buffer,
|
||||||
|
StaticDraw)
|
||||||
checkError "initBuffer"
|
checkError "initBuffer"
|
||||||
return (bo,len)
|
return (bo,len)
|
||||||
|
|
||||||
|
@ -77,10 +77,10 @@ lookAtUniformMatrix4fv :: (Double, Double, Double) --origin
|
|||||||
lookAtUniformMatrix4fv o c u frust num size = allocaArray 16 $ \projMat ->
|
lookAtUniformMatrix4fv o c u frust num size = allocaArray 16 $ \projMat ->
|
||||||
do
|
do
|
||||||
pokeArray projMat $
|
pokeArray projMat $
|
||||||
[1, 0, 0, 0,
|
[0.1, 0, 0, 0,
|
||||||
0, 0, 1, 0,
|
0, 0, 0.1, 0,
|
||||||
0, 1, 0, 0,
|
0, 0.1, 0, 0,
|
||||||
0, 0, 0, 1
|
0, 0, 0, 1
|
||||||
]
|
]
|
||||||
--(lookAt o c u) >< frust
|
--(lookAt o c u) >< frust
|
||||||
glUniformMatrix4fv num size 1 projMat
|
glUniformMatrix4fv num size 1 projMat
|
||||||
|
Loading…
Reference in New Issue
Block a user