Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /examples/brick/shader.sml
ViewVC logotype

View of /examples/brick/shader.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 204 - (download) (annotate)
Mon Jun 16 15:26:10 2008 UTC (11 years, 1 month ago) by jhr
File size: 1475 byte(s)
  Track changes to ShaderLang API.
(* shader.sml
 *
 * COPYRIGHT (c) 2006 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.
 *)

structure Shader =
  struct

    structure SL = ShaderLang

    fun loadShader (create, fileName) = let
	  val inStrm = TextIO.openIn fileName
	  val src = TextIO.inputAll inStrm
	  val id = create()
	  in
	    TextIO.closeIn inStrm;
	    SL.shaderSource (id, [src]);
	    SL.compileShader id;
	    if (SL.compileStatus id)
	      then ()
	      else raise Fail(SL.shaderLog id);
	    id
	  end

    fun installShaders () = let
	  val brickVS = loadShader (SL.createVertexShader, "brick.vert")
	  val brickFS = loadShader (SL.createFragmentShader, "brick.frag")
	(* build program *)
	  val brickProg = SL.createProgram()
	  val _ = SL.attachShader (brickProg, brickVS)
	  val _ = SL.attachShader (brickProg, brickFS)
	  in
	  (* link the program *)
	    SL.linkProgram brickProg;
	    if SL.linkStatus brickProg
	      then ()
	      else raise Fail(SL.programLog brickProg);
	    SL.useProgram (SOME brickProg);
	  (* setup initial uniform values *)
	    SL.uniform3f (SL.lookupUniform (brickProg, "BrickColor")) (1.0, 0.3, 0.2);
	    SL.uniform3f (SL.lookupUniform (brickProg, "MortarColor")) (0.85, 0.86, 0.84);
	    SL.uniform2f (SL.lookupUniform (brickProg, "BrickSize")) (0.30, 0.15);
	    SL.uniform2f (SL.lookupUniform (brickProg, "BrickPct")) (0.90, 0.85);
	    SL.uniform3f (SL.lookupUniform (brickProg, "LightPosition")) (0.0, 0.0, 4.0)
	  end

  end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0