Difference between revisions of "GPU (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Moved to CAT:UnofficialAPIs)
 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The GPU api provides interaction with and is part of the [[CCGPU]] peripheral.
+
The GPU api provides interaction with and is part of the [[CCGPU]] peripheral.<br>
 +
''Arguments surrounded with square brackets are optional.''
 +
 
 +
== API Methods ==
 +
''These methods can be used in any ComputerCraft program if the CCGPU api is installed.''
 
{| border="1" cellpadding="2" cellspacing="0"
 
{| border="1" cellpadding="2" cellspacing="0"
 
!style="background:#EEE" width="380px"|Method name
 
!style="background:#EEE" width="380px"|Method name
 
!style="background:#EEE" width="*"|Description
 
!style="background:#EEE" width="*"|Description
 
|-
 
|-
|[[gpu.setRenderCode(side, renderCode)]]
+
|gpu.getID(<nowiki>[</nowiki>side<nowiki>]</nowiki>)
 +
|Returns the ID of the GPU on the given side.
 +
|-
 +
|gpu.setRenderCode(<nowiki>[</nowiki>side<nowiki>]</nowiki>, renderCode)
 
|Sets the gpu rendering code, this code is ran every frame.<br />
 
|Sets the gpu rendering code, this code is ran every frame.<br />
''@param'' '''side''' the side the gpu is connected to<br />
+
|-
''@param'' '''renderCode''' the code as a string<br />
+
|gpu.loadRenderCode(<nowiki>[</nowiki>side<nowiki>]</nowiki>, filePath)
''@return'' nil
+
|Equivalent to setting the render code, but loads it from a file.<br />
 +
|-
 +
|gpu.setVar(<nowiki>[</nowiki>side<nowiki>]</nowiki>, name, value)
 +
|coming soon
 +
|-
 +
|gpu.getLatestError(<nowiki>[</nowiki>side<nowiki>]</nowiki>)
 +
|Returns the last error that has been thrown by Lua in your render code.
 +
|}
 +
 
 +
== Render Methods ==
 +
''These methods can be used in render code when set using '''gpu.setRenderCode'''.''
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
!style="background:#EEE" width="380px"|Method name
 +
!style="background:#EEE" width="*"|Description
 +
|-
 +
|gpuCreateBuffer(width, height)
 +
|Coming soon
 +
|-
 +
|gpuClearBuffer()
 +
|Clear the currently bound buffer.
 +
|-
 +
|gpuBindBuffer(id)
 +
|coming soon
 +
|-
 +
|gpuBindOutputBuffer(id)
 +
|Start drawing to a different buffer. (Set this to a certain monitor ID to draw to it.)
 +
|-
 +
|gpuGetOutputResolution(id)
 +
|Coming soon
 +
|}
 +
 
 +
== OpenGL Methods ==
 +
''These methods are part of [http://en.wikipedia.org/wiki/OpenGL OpenGL] and can only be used in render code when set using '''gpu.setRenderCode'''.''
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
!style="background:#EEE" width="380px"|Method name
 +
!style="background:#EEE" width="*"|Description
 +
|-
 +
|glBegin(mode)
 +
|Begins drawing something (Begins GL scope). mode should be a constant like GL_QUADS or GL_TRIANGLES. You must invoke this function before setting vertices for the shape.
 +
|-
 +
|glEnd()
 +
|Invoke this when you've set all your vertices (Ends GL scope).
 +
|-
 +
|glBindTexture(id)
 +
|Coming soon
 +
|-
 +
|glTexCoord2f(x, y)
 +
|Coming soon
 +
|-
 +
|glVertex2f(x, y)
 +
|Use this between glBegin(mode) and glEnd() to set a 2D vertex.
 +
|-
 +
|glVertex3f(x, y, z)
 +
|Use this between glBegin(mode) and glEnd() to set a 3D vertex.
 +
|-
 +
|glColor3f(red, green, blue)
 +
|Use this between glBegin(mode) and glEnd() to set the color.
 +
|-
 +
|glColor4f(red, green, blue, alpha)
 +
|Use this between glBegin(mode) and glEnd() to set the color with alpha (opacity).
 +
|}
 +
 
 +
== OpenGL Constants ==
 +
''These constants are part of [http://en.wikipedia.org/wiki/OpenGL OpenGL] and can only be used in render code when set using '''gpu.setRenderCode'''.''
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
!style="background:#EEE" width="380px"|Constant name
 +
!style="background:#EEE" width="*"|Description
 +
|-
 +
|GL_QUADS
 +
|Constant for drawing a quadrilateral.
 +
|-
 +
|GL_TRIANGLES
 +
|Constant for drawing a triangle.
 +
|-
 +
|GL_POINTS
 +
|Constant for drawing a pixel at each vertex given.
 +
|}
 +
''Although some constants are not yet included in the API, they can already be used. Therefore you have to pass in the value which is associated with the constant.''
 +
{| border="1" cellpadding="2" cellspacing="0"
 +
!style="background:#EEE" width="190px"|Associated value
 +
!style="background:#EEE" width="190px"|Constant name
 +
!style="background:#EEE" width="*"|Description
 +
|-
 +
|1
 +
|GL_LINES
 +
|Value for drawing a line.
 +
|-
 +
|2
 +
|GL_LINE_LOOP
 +
|Value for drawing a line loop.
 +
|-
 +
|3
 +
|GL_LINE_STRIP
 +
|Value for drawing a line strip.
 +
|-
 +
|5
 +
|GL_TRIANGLE_STRIP
 +
|Value for drawing a triangle strip.
 +
|-
 +
|6
 +
|GL_TRIANGLE_FAN
 +
|Value for drawing a triangle fan.
 +
|-
 +
|8
 +
|GL_QUAD_STRIP
 +
|Value for drawing a quad strip.
 +
|-
 +
|9
 +
|GL_POLYGON
 +
|Value for drawing a convex polygon.
 
|}
 
|}
 +
 +
[[Category:Unofficial_APIs]]

Latest revision as of 16:03, 28 November 2012

The GPU api provides interaction with and is part of the CCGPU peripheral.
Arguments surrounded with square brackets are optional.

API Methods

These methods can be used in any ComputerCraft program if the CCGPU api is installed.

Method name Description
gpu.getID([side]) Returns the ID of the GPU on the given side.
gpu.setRenderCode([side], renderCode) Sets the gpu rendering code, this code is ran every frame.
gpu.loadRenderCode([side], filePath) Equivalent to setting the render code, but loads it from a file.
gpu.setVar([side], name, value) coming soon
gpu.getLatestError([side]) Returns the last error that has been thrown by Lua in your render code.

Render Methods

These methods can be used in render code when set using gpu.setRenderCode.

Method name Description
gpuCreateBuffer(width, height) Coming soon
gpuClearBuffer() Clear the currently bound buffer.
gpuBindBuffer(id) coming soon
gpuBindOutputBuffer(id) Start drawing to a different buffer. (Set this to a certain monitor ID to draw to it.)
gpuGetOutputResolution(id) Coming soon

OpenGL Methods

These methods are part of OpenGL and can only be used in render code when set using gpu.setRenderCode.

Method name Description
glBegin(mode) Begins drawing something (Begins GL scope). mode should be a constant like GL_QUADS or GL_TRIANGLES. You must invoke this function before setting vertices for the shape.
glEnd() Invoke this when you've set all your vertices (Ends GL scope).
glBindTexture(id) Coming soon
glTexCoord2f(x, y) Coming soon
glVertex2f(x, y) Use this between glBegin(mode) and glEnd() to set a 2D vertex.
glVertex3f(x, y, z) Use this between glBegin(mode) and glEnd() to set a 3D vertex.
glColor3f(red, green, blue) Use this between glBegin(mode) and glEnd() to set the color.
glColor4f(red, green, blue, alpha) Use this between glBegin(mode) and glEnd() to set the color with alpha (opacity).

OpenGL Constants

These constants are part of OpenGL and can only be used in render code when set using gpu.setRenderCode.

Constant name Description
GL_QUADS Constant for drawing a quadrilateral.
GL_TRIANGLES Constant for drawing a triangle.
GL_POINTS Constant for drawing a pixel at each vertex given.

Although some constants are not yet included in the API, they can already be used. Therefore you have to pass in the value which is associated with the constant.

Associated value Constant name Description
1 GL_LINES Value for drawing a line.
2 GL_LINE_LOOP Value for drawing a line loop.
3 GL_LINE_STRIP Value for drawing a line strip.
5 GL_TRIANGLE_STRIP Value for drawing a triangle strip.
6 GL_TRIANGLE_FAN Value for drawing a triangle fan.
8 GL_QUAD_STRIP Value for drawing a quad strip.
9 GL_POLYGON Value for drawing a convex polygon.