Blah
authorLuke Lau <luke_lau@icloud.com>
Tue, 25 Sep 2018 11:01:07 +0000 (12:01 +0100)
committerLuke Lau <luke_lau@icloud.com>
Tue, 25 Sep 2018 11:01:07 +0000 (12:01 +0100)
part1.png [new file with mode: 0644]
part2.png [new file with mode: 0644]
part4.png [new file with mode: 0644]
report.aux [new file with mode: 0644]
report.latex [new file with mode: 0644]
report.log [new file with mode: 0644]
report.pdf [new file with mode: 0644]

diff --git a/part1.png b/part1.png
new file mode 100644 (file)
index 0000000..30c8342
Binary files /dev/null and b/part1.png differ
diff --git a/part2.png b/part2.png
new file mode 100644 (file)
index 0000000..e3af0e2
Binary files /dev/null and b/part2.png differ
diff --git a/part4.png b/part4.png
new file mode 100644 (file)
index 0000000..5867e1a
Binary files /dev/null and b/part4.png differ
diff --git a/report.aux b/report.aux
new file mode 100644 (file)
index 0000000..423bc3d
--- /dev/null
@@ -0,0 +1,7 @@
+\relax 
+\@writefile{toc}{\contentsline {section}{\numberline {1}Fragment shader colours}{1}}
+\@writefile{lol}{\contentsline {lstlisting}{fragment.glsl}{1}}
+\@writefile{toc}{\contentsline {section}{\numberline {2}Two triangles}{2}}
+\@writefile{toc}{\contentsline {section}{\numberline {3}Two triangles, two VAOs and two VBOs}{3}}
+\@writefile{toc}{\contentsline {section}{\numberline {4}Two separate shaders}{4}}
+\@writefile{lol}{\contentsline {lstlisting}{yellow.glsl}{5}}
diff --git a/report.latex b/report.latex
new file mode 100644 (file)
index 0000000..3193a7e
--- /dev/null
@@ -0,0 +1,203 @@
+\documentclass{article}
+\usepackage{fullpage}
+\usepackage{listings}
+\usepackage{graphicx}
+\begin{document}
+
+\author{Luke Lau}
+\title{CS4052 Assignment 1}
+\maketitle
+
+\lstset{basicstyle=\ttfamily}
+
+\section{Fragment shader colours}
+In order to get the fragment shader to use the position as the colour,
+I had to add an input \texttt{vec4} for the \texttt{vec4 color} that the vertex shader
+outputted. Since the inputs to the fragment shader are from the vertex shader, I had to
+use \texttt{color} and not \texttt{vColor}.
+\lstinputlisting[language=C++]{fragment.glsl}
+\begin{center}
+       \includegraphics[width=0.8\textwidth]{part1}
+\end{center}
+
+
+\section{Two triangles}
+
+Two add two triangles, I had to increase the number of vertices drawn to 6
+
+\begin{lstlisting}[language=C++]
+glDrawArrays(GL_TRIANGLES, 0, 6);
+\end{lstlisting}
+
+And add 9 new coordinates and colours for them.
+
+\begin{lstlisting}[language=C++]
+GLfloat vertices[] = {
+       0.0f, -1.0f, 0.0f,
+       1.0f, -1.0f, 0.0f,
+       0.5f, 1.0f, 0.0f,
+       -1.0f, -1.0f, 0.0f,
+       0.0f, -1.0f, 0.0f,
+       -0.5f, 1.0f, 0.0f
+}
+GLfloat colors[] = {
+       0, 1, 0, 1,
+       1, 0, 0, 1,
+       0, 0, 1, 1,
+       0, 1, 0, 1,
+       1, 0, 0, 1,
+       0, 0, 1, 1              
+};
+\end{lstlisting}
+
+\begin{center}
+       \includegraphics[width=0.8\textwidth]{part2}
+\end{center}
+
+
+\section{Two triangles, two VAOs and two VBOs}
+
+In order to use two VAOs and two VBOs, I had to combine the VAO setup and the VBO setup
+into one function, since you need to bind the VBO at the time that you create the 
+corresponding VAO.
+
+\begin{lstlisting}[language=C++]
+#define BUFFER_OFFSET(i) ((char *)NULL + (i))
+
+GLuint setupBuffers(GLfloat* vertices, GLuint progId) {
+
+       GLfloat colors[] = {
+               0, 1, 0, 1,
+               1, 0, 0, 1,
+               0, 0, 1, 1
+       };
+
+       GLuint numVerts = 3;
+
+       GLuint vbo;
+       glGenBuffers(1, &vbo);
+
+       GLuint vao;
+       glGenVertexArrays(1, &vao);
+
+       GLuint posId = glGetAttribLocation(progId, "vPosition");
+       GLuint colorId = glGetAttribLocation(progId, "vColor");
+
+       GLuint vertsLen = numVerts * 3 * sizeof(GLfloat);
+       GLuint colorsLen = numVerts * 4 * sizeof(GLfloat);
+
+       glBindBuffer(GL_ARRAY_BUFFER, vbo);
+       glBufferData(GL_ARRAY_BUFFER, vertsLen + colorsLen, NULL, GL_STATIC_DRAW);
+
+       glBufferSubData(GL_ARRAY_BUFFER, 0, vertsLen, vertices);
+       glBufferSubData(GL_ARRAY_BUFFER, vertsLen, colorsLen, colors);
+       
+       glBindVertexArray(vao);
+
+       glEnableVertexAttribArray(posId);
+       glEnableVertexAttribArray(colorId);
+       
+       glVertexAttribPointer(posId, 3, GL_FLOAT, GL_FALSE, 0, 0);
+       glVertexAttribPointer(colorId, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(numVerts * 3 * sizeof(GLfloat)));
+
+       return vao;
+}
+\end{lstlisting}
+
+This could then be used like so:
+\begin{lstlisting}[language=C++]
+GLfloat vertices[2][9] = {
+       {
+               0.0f, -1.0f, 0.0f,
+               1.0f, -1.0f, 0.0f,
+               0.5f, 1.0f, 0.0f
+       },
+
+       {
+               -1.0f, -1.0f, 0.0f,
+               0.0f, -1.0f, 0.0f,
+               -0.5f, 1.0f, 0.0f
+       }
+};
+GLuint* vaos = new GLuint[2];
+vaos[0] = setupBuffers(vertices[0], progId);
+vaos[1] = setupBuffers(vertices[1], progId);
+\end{lstlisting}
+
+When drawing, the VAOs needed to be switched out:
+
+\begin{lstlisting}[language=C++]
+void display() {
+       glClear(GL_COLOR_BUFFER_BIT);
+       for (int i = 0; i < 2; i++) {
+               glBindVertexArray(vaos[i]);
+               glDrawArrays(GL_TRIANGLES, 0, 3);
+       }
+       glutSwapBuffers();
+}
+\end{lstlisting}
+
+\section{Two separate shaders}
+
+I modified the \texttt{compileShaders} function to load in the shader source from a file:
+\begin{lstlisting}[language=C++]
+GLuint compileShaders(char* vertexShader, char* fragmentShader) {
+       GLuint progId = glCreateProgram();
+
+       attachShader(progId, vertexShader, GL_VERTEX_SHADER);
+       attachShader(progId, fragmentShader, GL_FRAGMENT_SHADER);
+
+       glLinkProgram(progId);
+       GLint success = 0;
+       glGetProgramiv(progId, GL_LINK_STATUS, &success);
+       if (!success) {
+               GLchar log[1024];
+               glGetProgramInfoLog(progId, sizeof(log), NULL, log);
+               fprintf(stderr, "error linking: %s\n", log);
+               exit(1);
+       }
+
+       return progId;
+}
+\end{lstlisting}
+
+Which meant I could easily swap out the programs used when setting up the buffers:
+
+\begin{lstlisting}[language=C++]
+progIds = new GLuint[2];
+
+GLuint progId1 = compileShaders((char*)"vertex.glsl", (char*)"fragment.glsl");
+vaos[0] = setupBuffers(vertices[0], progId1);
+progIds[0] = progId1;
+validateProgram(progId1);
+
+GLuint progId2 = compileShaders((char*)"vertex.glsl", (char*)"yellow.glsl");
+vaos[1] = setupBuffers(vertices[1], progId2);
+progIds[1] = progId2;
+validateProgram(progId2);
+\end{lstlisting}
+
+The new yellow shader looked like this:
+
+\lstinputlisting[language=C++]{yellow.glsl}
+
+I needed to switch programs during the display function:
+
+\begin{lstlisting}[language=C++]
+void display() {
+       glClear(GL_COLOR_BUFFER_BIT);
+       for (int i = 0; i < 2; i++) {
+               glUseProgram(progIds[i]);
+               glBindVertexArray(vaos[i]);
+               glDrawArrays(GL_TRIANGLES, 0, 3);
+       }
+       glutSwapBuffers();
+}
+\end{lstlisting}
+
+\begin{center}
+       \includegraphics[width=0.8\textwidth]{part4}
+\end{center}
+
+
+\end{document}
diff --git a/report.log b/report.log
new file mode 100644 (file)
index 0000000..60a3ea9
--- /dev/null
@@ -0,0 +1,244 @@
+This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdflatex 2018.9.19)  22 SEP 2018 16:52
+entering extended mode
+ restricted \write18 enabled.
+ %&-line parsing enabled.
+**report.latex
+(./report.latex
+LaTeX2e <2018-04-01> patch level 2
+Babel <3.18> and hyphenation patterns for 22 language(s) loaded.
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/article.cls
+Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/base/size10.clo
+File: size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
+)
+\c@part=\count80
+\c@section=\count81
+\c@subsection=\count82
+\c@subsubsection=\count83
+\c@paragraph=\count84
+\c@subparagraph=\count85
+\c@figure=\count86
+\c@table=\count87
+\abovecaptionskip=\skip41
+\belowcaptionskip=\skip42
+\bibindent=\dimen102
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/preprint/fullpage.sty
+Package: fullpage 1999/02/23 1.1 (PWD)
+\FP@margin=\skip43
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/listings.sty
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/keyval.sty
+Package: keyval 2014/10/28 v1.15 key=value parser (DPC)
+\KV@toks@=\toks14
+)
+\lst@mode=\count88
+\lst@gtempboxa=\box26
+\lst@token=\toks15
+\lst@length=\count89
+\lst@currlwidth=\dimen103
+\lst@column=\count90
+\lst@pos=\count91
+\lst@lostspace=\dimen104
+\lst@width=\dimen105
+\lst@newlines=\count92
+\lst@lineno=\count93
+\lst@maxwidth=\dimen106
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstmisc.sty
+File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
+\c@lstnumber=\count94
+\lst@skipnumbers=\count95
+\lst@framebox=\box27
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/listings.cfg
+File: listings.cfg 2015/06/04 1.6 listings configuration
+))
+Package: listings 2015/06/04 1.6 (Carsten Heinz)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/graphicx.sty
+Package: graphicx 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/graphics.sty
+Package: graphics 2017/06/25 v1.2c Standard LaTeX Graphics (DPC,SPQR)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics/trig.sty
+Package: trig 2016/01/03 v1.10 sin cos tan (DPC)
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics-cfg/graphics.cfg
+File: graphics.cfg 2016/06/04 v1.11 sample graphics configuration
+)
+Package graphics Info: Driver file: pdftex.def on input line 99.
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/graphics-def/pdftex.def
+File: pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
+))
+\Gin@req@height=\dimen107
+\Gin@req@width=\dimen108
+)
+(./report.aux)
+\openout1 = `report.aux'.
+
+LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line 5.
+LaTeX Font Info:    ... okay on input line 5.
+\c@lstlisting=\count96
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
+[Loading MPS to PDF converter (version 2006.09.02).]
+\scratchcounter=\count97
+\scratchdimen=\dimen109
+\scratchbox=\box28
+\nofMPsegments=\count98
+\nofMParguments=\count99
+\everyMPshowfont=\toks16
+\MPscratchCnt=\count100
+\MPscratchDim=\dimen110
+\MPnumerator=\count101
+\makeMPintoPDFobject=\count102
+\everyMPtoPDFconversion=\toks17
+) (/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
+Package: epstopdf-base 2016/05/15 v2.6 Base part for package epstopdf
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/infwarerr.sty
+Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/grfext.sty
+Package: grfext 2016/05/16 v1.2 Manage graphics extensions (HO)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty
+Package: kvdefinekeys 2016/05/16 v1.4 Define keys (HO)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ltxcmds.sty
+Package: ltxcmds 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
+)))
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/oberdiek/kvoptions.sty
+Package: kvoptions 2016/05/16 v3.12 Key value format for package options (HO)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
+Package: kvsetkeys 2016/05/16 v1.17 Key value parser (HO)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/etexcmds.sty
+Package: etexcmds 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ifluatex.sty
+Package: ifluatex 2016/05/16 v1.4 Provides the ifluatex switch (HO)
+Package ifluatex Info: LuaTeX not detected.
+)
+Package etexcmds Info: Could not find \expanded.
+(etexcmds)             That can mean that you are not using pdfTeX 1.50 or
+(etexcmds)             that some package has redefined \expanded.
+(etexcmds)             In the latter case, load this package earlier.
+)))
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
+Package: pdftexcmds 2018/01/30 v0.27 Utility functions of pdfTeX for LuaTeX (HO
+)
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/generic/oberdiek/ifpdf.sty
+Package: ifpdf 2017/03/15 v3.2 Provides the ifpdf switch
+)
+Package pdftexcmds Info: LuaTeX not detected.
+Package pdftexcmds Info: \pdf@primitive is available.
+Package pdftexcmds Info: \pdf@ifprimitive is available.
+Package pdftexcmds Info: \pdfdraftmode found.
+)
+Package epstopdf-base Info: Redefining graphics rule for `.eps' on input line 4
+38.
+Package grfext Info: Graphics extension search list:
+(grfext)             [.pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,.PDF,.PNG,.JPG,.JPE
+G,.JBIG2,.JB2,.eps]
+(grfext)             \AppendGraphicsExtensions on input line 456.
+
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg
+File: epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Liv
+e
+))
+LaTeX Font Info:    External font `cmex10' loaded for size
+(Font)              <12> on input line 9.
+LaTeX Font Info:    External font `cmex10' loaded for size
+(Font)              <8> on input line 9.
+LaTeX Font Info:    External font `cmex10' loaded for size
+(Font)              <6> on input line 9.
+ (/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstlang1.sty
+File: lstlang1.sty 2015/06/04 1.6 listings language file
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstlang1.sty
+File: lstlang1.sty 2015/06/04 1.6 listings language file
+)
+(/usr/local/texlive/2018basic/texmf-dist/tex/latex/listings/lstmisc.sty
+File: lstmisc.sty 2015/06/04 1.6 (Carsten Heinz)
+)
+(./fragment.glsl
+LaTeX Font Info:    Font shape `OT1/cmtt/bx/n' in size <10> not available
+(Font)              Font shape `OT1/cmtt/m/n' tried instead on input line 1.
+)
+<part1.png, id=1, 915.42pt x 736.7525pt>
+File: part1.png Graphic file (type png)
+<use part1.png>
+Package pdftex.def Info: part1.png  used on input line 20.
+(pdftex.def)             Requested size: 375.80544pt x 302.4527pt.
+ [1
+
+{/usr/local/texlive/2018basic/texmf-var/fonts/map/pdftex/updmap/pdftex.map} <./
+part1.png>]
+<part2.png, id=14, 915.42pt x 736.7525pt>
+File: part2.png Graphic file (type png)
+<use part2.png>
+Package pdftex.def Info: part2.png  used on input line 54.
+(pdftex.def)             Requested size: 375.80544pt x 302.4527pt.
+ [2 <./part2.png>]
+Overfull \hbox (46.84398pt too wide) in paragraph at lines 90--92
+[][][][][][][][][][][][][][][][][][][][] 
+ []
+
+
+Overfull \hbox (235.84361pt too wide) in paragraph at lines 101--103
+[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
+ []
+
+[3]
+Overfull \hbox (21.64403pt too wide) in paragraph at lines 169--170
+[][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
+ []
+
+[4]
+Overfull \hbox (9.04405pt too wide) in paragraph at lines 174--175
+[][][][][][][][][][][][][][][][][][][][][][][][][][][][] 
+ []
+
+(./yellow.glsl)
+<part4.png, id=25, 915.42pt x 736.7525pt>
+File: part4.png Graphic file (type png)
+<use part4.png>
+Package pdftex.def Info: part4.png  used on input line 199.
+(pdftex.def)             Requested size: 375.80544pt x 302.4527pt.
+ [5 <./part4.png>] (./report.aux) ) 
+Here is how much of TeX's memory you used:
+ 3356 strings out of 494091
+ 46707 string characters out of 6163523
+ 147119 words of memory out of 5000000
+ 7005 multiletter control sequences out of 15000+600000
+ 7448 words of font info for 27 fonts, out of 8000000 for 9000
+ 319 hyphenation exceptions out of 8191
+ 41i,6n,61p,275b,1582s stack positions out of 5000i,500n,10000p,200000b,80000s
+</usr/local/texlive/2018basic/texmf-dist/fon
+ts/type1/public/amsfonts/cm/cmbx12.pfb></usr/local/texlive/2018basic/texmf-dist
+/fonts/type1/public/amsfonts/cm/cmr10.pfb></usr/local/texlive/2018basic/texmf-d
+ist/fonts/type1/public/amsfonts/cm/cmr12.pfb></usr/local/texlive/2018basic/texm
+f-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb></usr/local/texlive/2018basic/t
+exmf-dist/fonts/type1/public/amsfonts/cm/cmtt10.pfb>
+Output written on report.pdf (5 pages, 843858 bytes).
+PDF statistics:
+ 47 PDF objects out of 1000 (max. 8388607)
+ 28 compressed objects within 1 object stream
+ 0 named destinations out of 1000 (max. 500000)
+ 16 words of extra memory for PDF output out of 10000 (max. 10000000)
+
diff --git a/report.pdf b/report.pdf
new file mode 100644 (file)
index 0000000..151070b
Binary files /dev/null and b/report.pdf differ