diff options
-rw-r--r-- | Graphics/Glyph/BufferBuilder.hs | 16 | ||||
-rw-r--r-- | Hw8.hs | 26 | ||||
-rw-r--r-- | README | 46 | ||||
-rw-r--r-- | shaders/textured.frag | 2 |
4 files changed, 63 insertions, 27 deletions
diff --git a/Graphics/Glyph/BufferBuilder.hs b/Graphics/Glyph/BufferBuilder.hs index e43e48a..4c56c6f 100644 --- a/Graphics/Glyph/BufferBuilder.hs +++ b/Graphics/Glyph/BufferBuilder.hs @@ -99,20 +99,20 @@ compilingBuilder (Builder lst _) = do where (?) True = 1 (?) False = 0 -- Cur color normal texture buffer - let (_,_,_,buffer) = - Fold.foldl (\(cn,cc,ct,ll) ele -> + let (nverts,_,_,_,buffer) = + Fold.foldl (\(num,cn,cc,ct,ll) ele -> -- trace ("foldl " ++! ele) $ case ele of - NormalLink nn -> (nn,cc,ct,ll) - ColorLink nc -> (cn,nc,ct,ll) - TextureLink nt -> (cn,cc,nt,ll) + NormalLink nn -> (num,nn,cc,ct,ll) + ColorLink nc -> (num,cn,nc,ct,ll) + TextureLink nt -> (num,cn,cc,nt,ll) VertexLink vert -> - (cn,cc,ct, + (num+1,cn,cc,ct, ll >< (tp3 True vert >< tp3 bn cn >< tp4 bc cc >< tp2 bt ct) - )) ( (0,0,0), (0,0,0,0), (0,0), Seq.empty ) (Seq.reverse lst) + )) ( 0, (0,0,0), (0,0,0,0), (0,0), Seq.empty ) (Seq.reverse lst) arr <- newListArray (0,Seq.length buffer) (Fold.toList buffer) - ((putStrLn.("Compiled: "++!))>&>return) $ CompiledBuild stride en (Seq.length buffer `div` stride * sizeof) arr + ((putStrLn.("Compiled: "++!))>&>return) $ CompiledBuild stride en nverts arr where @@ -93,7 +93,7 @@ instance Drawable (GlyphObject a) where vertexAttribPointer attr $= (ToFloat, ad) vertexAttribArray attr $= Enabled - drawArrays Quads 0 (bufferLength co) + drawArrays Triangles 0 (bufferLength co) forM_ enabled $ \(attr, _) -> do vertexAttribArray attr $= Disabled @@ -202,20 +202,22 @@ loadBackdropProgram = do quad :: Builder GLfloat () quad = do - forM_ [ - (-1,-1,0.0), - (-1, 1,0.0), - ( 1, 1,0.0), - ( 1,-1,0.0) - ] $ \(a,b,c) -> do - bVertex3 (a,b,c) + let lst = [ (-1,-1,0.0), + (-1, 1,0.0), + ( 1, 1,0.0) ] + let neg (a,b,c) = (-a,-b,-c) + + forM_ lst bVertex3 + forM_ lst (bVertex3.neg) + circle :: GLfloat -> GLfloat -> Builder GLfloat () circle r step = do - let lst = concat [[(r,th-step,ph-step), - (r,th+step,ph-step), - (r,th+step,ph+step), - (r,th-step,ph+step)] + let fromQuad (a,b,c,d) = [a,b,c,b,c,d] + let lst = concat [fromQuad ((r,th-step,ph-step), + (r,th+step,ph-step), + (r,th+step,ph+step), + (r,th-step,ph+step)) | th <- [0,step..359-step], ph <- [-90,-90+step..89-step]] mapM_ ( doUv >&> ((bNormal3 >&> bVertex3) . toEuclidian) ) lst @@ -1,10 +1,44 @@ -This was a tough one to get to work with Haskell. Apparently pretty much all of the OpenCV Haskell bindings -are broken/half-implemented, so I had to create my own with FFI. +This was a long assignment mostly because I decided to learn vertex buffers +once and for all. This project is 100% delicious Haskell goodness with 0% fixed +pipeline. Everything is OpenGL 4 complient right down to using only triangles, +which means I had all kinds of fun reinventing the wheel reimplementing vector +math and looking up algorithms for creating a lookat matrix using GLM as a +reference. -As usual, I have provided a statically linked binary just in case. +I honestly would not be entirely surprised if I am one of the only people to +actually have accomplished this. Not sure if this is a good thing or a bad +thing, but whatever it is, I managed to put together a proof of concept. -This project took me about 8 to 10 hours to complete. +The good news is that I know not only understand how vertex buffers work, but I +also understand OpenGL much better than I used to. Once I got simple lighting +to work, this project was quite a bit of fun. -make with make +This project is a mimic of the Blue Marble example, except with some +adjustments. First, the moon is in the scene as a test to see if I could make +another object in the scene easily. Both the Earth and the Moon are bump +mapped, correctly I think. I pass in a random texture to add randomness to the +shader for when I decide when to turn on and off lights. + +The earth has clouds which rotate faster than the Earth itself so they appear +to be above the surface. The clouds also cast shadows on to the earth (fixed +offset, not actually calculated based on the light vector :-( ) And when the +shadows appear over land, there is a random chance that a light may turn on, +after all, people turn on lights during a storm. + +I also use the noise texture to have each light alternate between two colors +to give the appearance of twinkling. + +I realize the background texture does not move with the camera, this is by +design. I wanted to try to draw a scene with a completely different model view +matrix and projection matrix in the same rendering. It worked. + +To compile run make, run with - ./jora2470_hw7 +./jora2470_hw8 + +Controls: + +UP/DOWN/LEFT/RIGHT: Move camera around center +w/s: zoom in and out. +n: change to random bump map +=/-: speed up/slow down time diff --git a/shaders/textured.frag b/shaders/textured.frag index 266bf31..0ba7c48 100644 --- a/shaders/textured.frag +++ b/shaders/textured.frag @@ -126,7 +126,7 @@ void main() { * a function of time to simulate twinkling */ tmpcolor *= mix( vec4(cmp.r*2.0,min(cmp.g,cmp.r)*1.5,min(cmp.b,cmp.r),1.0), - vec4(cmp2.r*2.0,min(cmp2.g,cmp2.r)*1.5,min(cmp2.b,cmp2.r),1.0), (sin(time*cmp2.a+cmp.a)+1.0)/2.0 ) ; + vec4(2.0,2.0,2.0,2.0), sin(time/10.0+cmp.a*27.3) ) ; tmpcolor -= cloudsColor; } |