Class FrameBuffer.Viewport
- java.lang.Object
-
- renderer.framebuffer.FrameBuffer.Viewport
-
- Enclosing class:
- FrameBuffer
public class FrameBuffer.Viewport extends Object
AViewportis an inner (non-static nested) class ofFrameBuffer. That means that aViewporthas access to the pixel data of its "parent"FrameBuffer.A
Viewportis a two-dimensional sub array of its "parent"FrameBuffer. AViewportis represented by its upper-left-hand corner and its lower-right-hand corner in theFrameBuffer.When you set a pixel in a
Viewport, you are really setting a pixel in its parentFrameBuffer.A
FrameBuffercan have multipleViewports.Viewportcoordinates act like JavaGraphics2Dcoordinates; the positivexdirection is to the right and the positiveydirection is downward.
-
-
Constructor Summary
Constructors Constructor Description Viewport()Create aViewportthat is the whole of its parentFrameBuffer.Viewport(int vp_ul_x, int vp_ul_y, int width, int height)Create aViewportwith the given upper-left-hand corner, width and height within its parentFrameBuffer.Viewport(int vp_ul_x, int vp_ul_y, int width, int height, Color c)Create aViewportwith the given upper-left-hand corner, width and height within its parentFrameBuffer, and with the given background color.Viewport(int vp_ul_x, int vp_ul_y, String inputFileName)Create aViewport, within its parentFrameBuffer, from a PPM image file.Viewport(int vp_ul_x, int vp_ul_y, FrameBuffer sourceFB)Viewport(int vp_ul_x, int vp_ul_y, FrameBuffer.Viewport sourceVP)Viewport(Color c)Create aViewportthat is the whole of its parentFrameBufferand with the given background color.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearVP()Clear thisViewportusing its background color.voidclearVP(Color c)Clear thisViewportusing the givenColor.FrameBufferconvertVP2FB()Create a newFrameBuffercontaining the pixel data from thisViewportrectangle.voiddumpVP2File(String filename)Write thisViewportto the specified PPM file.voiddumpVP2File(String filename, String formatName)Write thisViewportto the specified image file using the specified file format.ColorgetBackgroundColorVP()Get theViewport's background color.FrameBuffergetFrameBuffer()Return a reference to theFrameBufferobject that thisViewportobject is nested in.intgetHeightVP()Get the height of thisViewport.ColorgetPixelVP(int x, int y)intgetWidthVP()Get the width of thisViewport.voidsetBackgroundColorVP(Color c)Set theViewport's background color.voidsetPixelVP(int x, int y, int c)Set the combined RGB value of the pixel with coordinates(x,y)relative to thisViewport.voidsetPixelVP(int x, int y, Color c)voidsetViewport(int vp_ul_x, int vp_ul_y, int width, int height)Mutate thisViewportinto the given upper-left-hand corner, width and height within its parentFrameBuffer.voidvpTestPattern()A simple test of theViewport.
-
-
-
Constructor Detail
-
Viewport
public Viewport()
Create aViewportthat is the whole of its parentFrameBuffer. The default backgroundColoris theFrameBuffer's background color. (Note: This constructor does not set the pixels of thisViewport. If you want the pixels of thisViewportto be cleared to the background color, call theclearVP()method.)
-
Viewport
public Viewport(Color c)
Create aViewportthat is the whole of its parentFrameBufferand with the given background color. (Note: This constructor does not use the background color to set the pixels of thisViewport. If you want the pixels of thisViewportto be cleared to the background color, call theclearVP()method.)- Parameters:
c- backgroundColorfor theViewport
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, int width, int height)
Create aViewportwith the given upper-left-hand corner, width and height within its parentFrameBuffer. (Note: This constructor does not set the pixels of thisViewport. If you want the pixels of thisViewportto be cleared to the background color, call theclearVP()method.)- Parameters:
vp_ul_x- upper left hand x-coordinate of newViewportrectanglevp_ul_y- upper left hand y-coordinate of newViewportrectanglewidth-Viewport's widthheight-Viewport's height
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, int width, int height, Color c)
Create aViewportwith the given upper-left-hand corner, width and height within its parentFrameBuffer, and with the given background color. (Note: This constructor does not use the background color to set the pixels of thisViewport. If you want the pixels of thisViewportto be cleared to the background color, call theclearVP()method.)(Using upper-left-hand corner, width, and height is like Java's
Rectangleclass andGraphics.drawRect(int, int, int, int)method.)- Parameters:
vp_ul_x- upper left hand x-coordinate of newViewportrectanglevp_ul_y- upper left hand y-coordinate of newViewportrectanglewidth-Viewport's widthheight-Viewport's heightc- backgroundColorfor theViewport
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, FrameBuffer sourceFB)
Create aViewport, within its parentFrameBuffer, from the pixel data of anotherFrameBuffer.The size of the
Viewportwill be the size of the sourceFrameBuffer.- Parameters:
vp_ul_x- upper left hand x-coordinate of newViewportrectanglevp_ul_y- upper left hand y-coordinate of newViewportrectanglesourceFB-FrameBufferto use as the source of the pixel data
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, FrameBuffer.Viewport sourceVP)
Create aViewport, within its parentFrameBuffer, from the pixel data of aViewport.The size of the new
Viewportwill be the size of the sourceViewport.This constructor makes the new
Viewportinto a copy of the sourceViewport.- Parameters:
vp_ul_x- upper left hand x-coordinate of newViewportrectanglevp_ul_y- upper left hand y-coordinate of newViewportrectanglesourceVP-FrameBuffer.Viewportto use as the source of the pixel data
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, String inputFileName)
Create aViewport, within its parentFrameBuffer, from a PPM image file.The size of the
Viewportwill be the size of the image.This can be used to initialize a
Viewportwith a background image.- Parameters:
vp_ul_x- upper left hand x-coordinate of newViewportrectanglevp_ul_y- upper left hand y-coordinate of newViewportrectangleinputFileName- must name a PPM image file with magic number P6.
-
-
Method Detail
-
setViewport
public void setViewport(int vp_ul_x, int vp_ul_y, int width, int height)
Mutate thisViewportinto the given upper-left-hand corner, width and height within its parentFrameBuffer.(Using upper-left-hand corner, width, and height is like Java's
Rectangleclass andGraphics.drawRect(int, int, int, int)method.)- Parameters:
vp_ul_x- new upper left hand x-coordinate of thisViewportrectanglevp_ul_y- new upper left hand y-coordinate of thisViewportrectanglewidth-Viewport's new widthheight-Viewport's new height
-
getFrameBuffer
public FrameBuffer getFrameBuffer()
Return a reference to theFrameBufferobject that thisViewportobject is nested in.- Returns:
- a reference to the
FrameBufferobject that thisViewportis part of
-
getWidthVP
public int getWidthVP()
Get the width of thisViewport.- Returns:
- width of this
Viewportrectangle
-
getHeightVP
public int getHeightVP()
Get the height of thisViewport.- Returns:
- height of this
Viewportrectangle
-
getBackgroundColorVP
public Color getBackgroundColorVP()
Get theViewport's background color.- Returns:
- the
Viewport's backgroundColor
-
setBackgroundColorVP
public void setBackgroundColorVP(Color c)
Set theViewport's background color.NOTE: This method does not clear the pixels of the
Viewportto the givenColor. To actually change all theViewport's pixels to the givenColor, use theclearVP()method.- Parameters:
c-Viewport's new backgroundColor
-
clearVP
public void clearVP()
Clear thisViewportusing its background color.
-
clearVP
public void clearVP(Color c)
Clear thisViewportusing the givenColor.- Parameters:
c-Colorto clear thisViewportwith
-
getPixelVP
public Color getPixelVP(int x, int y)
- Parameters:
x- horizontal coordinate within thisViewporty- vertical coordinate within thisViewport- Returns:
- the
Colorof the current pixel at the givenViewportcoordinates
-
setPixelVP
public void setPixelVP(int x, int y, Color c)
- Parameters:
x- horizontal coordinate within thisViewporty- vertical coordinate within thisViewportc-Colorfor the pixel at the givenViewportcoordinates
-
setPixelVP
public void setPixelVP(int x, int y, int c)
Set the combined RGB value of the pixel with coordinates(x,y)relative to thisViewport.- Parameters:
x- horizontal coordinate within thisViewporty- vertical coordinate within thisViewportc- combined RGB value for the pixel at the givenViewportcoordinates
-
convertVP2FB
public FrameBuffer convertVP2FB()
Create a newFrameBuffercontaining the pixel data from thisViewportrectangle.- Returns:
FrameBufferobject holding pixel data from thisViewport
-
dumpVP2File
public void dumpVP2File(String filename)
Write thisViewportto the specified PPM file.- Parameters:
filename- name of PPM image file to holdViewportdata
-
dumpVP2File
public void dumpVP2File(String filename, String formatName)
Write thisViewportto the specified image file using the specified file format.- Parameters:
filename- name of the image file to holdViewportdataformatName- informal name of the image format
-
vpTestPattern
public void vpTestPattern()
A simple test of theViewport.It fills the viewport with a test pattern.
-
-