moooaaarrr work on triangles ... still nothing

This commit is contained in:
Nicole Dresselhaus 2014-01-04 02:45:13 +01:00
parent a2c1effb48
commit 7db4bff2e4
6 changed files with 42 additions and 14 deletions

View File

@ -25,5 +25,6 @@ executable Pioneers
pretty >=1.1,
transformers >=0.3.0 && <0.4,
mtl >=2.1.2,
stm >=2.4.2
stm >=2.4.2,
vector >=0.10.9 && <0.11

View File

@ -3,11 +3,10 @@
//color from earlier stages
smooth in vec4 fg_SmoothColor;
//color of pixel
out vec4 fg_FragColor;
void main(void)
{
//copy-shader
fg_FragColor = fg_SmoothColor;
fg_FragColor = vec4(1,0,0,1) + 0.01* fg_SmoothColor;
}

View File

@ -9,12 +9,12 @@ in vec3 fg_VertexIn;
in vec3 fg_Normal;
//output-data for later stages
smooth out vec4 fg_SmoothColor;
out vec4 fg_SmoothColor;
void main()
{
//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;
gl_Position = fg_ProjectionMatrix * fg_Vertex;
}

View File

@ -11,11 +11,13 @@ import Data.Maybe (catMaybes)
import Text.PrettyPrint
import qualified Graphics.Rendering.OpenGL.GL as GL
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 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
frust = stateFrustum state
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.vertexAttribPointer ci GL.$= fgColorIndex
GL.vertexAttribArray ci GL.$= GL.Enabled
GL.vertexAttribPointer ni GL.$= fgNormalIndex
GL.vertexAttribArray ni GL.$= GL.Enabled
GL.vertexAttribPointer vi GL.$= fgVertexIndex
GL.vertexAttribArray vi GL.$= GL.Enabled
GL.drawArrays GL.Triangles 0 numVert
checkError "draw"
getCursorKeyDirections :: GLFW.Window -> IO (Double, Double)
getCursorKeyDirections win = do

View File

@ -80,7 +80,9 @@ getMapBufferObject = do
bo <- genObjectName -- create a new buffer
bindBuffer ArrayBuffer $= Just bo -- bind 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"
return (bo,len)

View File

@ -77,9 +77,9 @@ lookAtUniformMatrix4fv :: (Double, Double, Double) --origin
lookAtUniformMatrix4fv o c u frust num size = allocaArray 16 $ \projMat ->
do
pokeArray projMat $
[1, 0, 0, 0,
0, 0, 1, 0,
0, 1, 0, 0,
[0.1, 0, 0, 0,
0, 0, 0.1, 0,
0, 0.1, 0, 0,
0, 0, 0, 1
]
--(lookAt o c u) >< frust