Class FrameBuffer.Viewport
- java.lang.Object
-
- renderer.framebuffer.FrameBuffer.Viewport
-
- Enclosing class:
- FrameBuffer
public class FrameBuffer.Viewport extends Object
AViewport
is an inner (non-static nested) class ofFrameBuffer
. That means that aViewport
has access to the pixel data of its "parent"FrameBuffer
.A
Viewport
is a two-dimensional sub array of its "parent"FrameBuffer
. AViewport
is 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
FrameBuffer
can have multipleViewport
s.Viewport
coordinates act like JavaGraphics2D
coordinates; the positivex
direction is to the right and the positivey
direction is downward.
-
-
Constructor Summary
Constructors Constructor Description Viewport()
Create aViewport
that is the whole of its parentFrameBuffer
.Viewport(int vp_ul_x, int vp_ul_y, int width, int height)
Create aViewport
with 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 aViewport
with 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 aViewport
that is the whole of its parentFrameBuffer
and with the given background color.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearVP()
Clear thisViewport
using its background color.void
clearVP(Color c)
Clear thisViewport
using the givenColor
.FrameBuffer
convertVP2FB()
Create a newFrameBuffer
containing the pixel data from thisViewport
rectangle.void
dumpVP2File(String filename)
Write thisViewport
to the specified PPM file.void
dumpVP2File(String filename, String formatName)
Write thisViewport
to the specified image file using the specified file format.Color
getBackgroundColorVP()
Get theViewport
's background color.FrameBuffer
getFrameBuffer()
Return a reference to theFrameBuffer
object that thisViewport
object is nested in.int
getHeightVP()
Get the height of thisViewport
.Color
getPixelVP(int x, int y)
int
getWidthVP()
Get the width of thisViewport
.void
setBackgroundColorVP(Color c)
Set theViewport
's background color.void
setPixelVP(int x, int y, int c)
Set the combined RGB value of the pixel with coordinates(x,y)
relative to thisViewport
.void
setPixelVP(int x, int y, Color c)
void
setViewport(int vp_ul_x, int vp_ul_y, int width, int height)
Mutate thisViewport
into the given upper-left-hand corner, width and height within its parentFrameBuffer
.void
vpTestPattern()
A simple test of theViewport
.
-
-
-
Constructor Detail
-
Viewport
public Viewport()
Create aViewport
that is the whole of its parentFrameBuffer
. The default backgroundColor
is theFrameBuffer
's background color. (Note: This constructor does not set the pixels of thisViewport
. If you want the pixels of thisViewport
to be cleared to the background color, call theclearVP()
method.)
-
Viewport
public Viewport(Color c)
Create aViewport
that is the whole of 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 thisViewport
to be cleared to the background color, call theclearVP()
method.)- Parameters:
c
- backgroundColor
for theViewport
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, int width, int height)
Create aViewport
with 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 thisViewport
to be cleared to the background color, call theclearVP()
method.)- Parameters:
vp_ul_x
- upper left hand x-coordinate of newViewport
rectanglevp_ul_y
- upper left hand y-coordinate of newViewport
rectanglewidth
-Viewport
's widthheight
-Viewport
's height
-
Viewport
public Viewport(int vp_ul_x, int vp_ul_y, int width, int height, Color c)
Create aViewport
with 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 thisViewport
to be cleared to the background color, call theclearVP()
method.)(Using upper-left-hand corner, width, and height is like Java's
Rectangle
class andGraphics.drawRect(int, int, int, int)
method.)- Parameters:
vp_ul_x
- upper left hand x-coordinate of newViewport
rectanglevp_ul_y
- upper left hand y-coordinate of newViewport
rectanglewidth
-Viewport
's widthheight
-Viewport
's heightc
- backgroundColor
for 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
Viewport
will be the size of the sourceFrameBuffer
.- Parameters:
vp_ul_x
- upper left hand x-coordinate of newViewport
rectanglevp_ul_y
- upper left hand y-coordinate of newViewport
rectanglesourceFB
-FrameBuffer
to 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
Viewport
will be the size of the sourceViewport
.This constructor makes the new
Viewport
into a copy of the sourceViewport
.- Parameters:
vp_ul_x
- upper left hand x-coordinate of newViewport
rectanglevp_ul_y
- upper left hand y-coordinate of newViewport
rectanglesourceVP
-FrameBuffer.Viewport
to 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
Viewport
will be the size of the image.This can be used to initialize a
Viewport
with a background image.- Parameters:
vp_ul_x
- upper left hand x-coordinate of newViewport
rectanglevp_ul_y
- upper left hand y-coordinate of newViewport
rectangleinputFileName
- 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 thisViewport
into the given upper-left-hand corner, width and height within its parentFrameBuffer
.(Using upper-left-hand corner, width, and height is like Java's
Rectangle
class andGraphics.drawRect(int, int, int, int)
method.)- Parameters:
vp_ul_x
- new upper left hand x-coordinate of thisViewport
rectanglevp_ul_y
- new upper left hand y-coordinate of thisViewport
rectanglewidth
-Viewport
's new widthheight
-Viewport
's new height
-
getFrameBuffer
public FrameBuffer getFrameBuffer()
Return a reference to theFrameBuffer
object that thisViewport
object is nested in.- Returns:
- a reference to the
FrameBuffer
object that thisViewport
is part of
-
getWidthVP
public int getWidthVP()
Get the width of thisViewport
.- Returns:
- width of this
Viewport
rectangle
-
getHeightVP
public int getHeightVP()
Get the height of thisViewport
.- Returns:
- height of this
Viewport
rectangle
-
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
Viewport
to 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 thisViewport
using its background color.
-
clearVP
public void clearVP(Color c)
Clear thisViewport
using the givenColor
.- Parameters:
c
-Color
to clear thisViewport
with
-
getPixelVP
public Color getPixelVP(int x, int y)
- Parameters:
x
- horizontal coordinate within thisViewport
y
- vertical coordinate within thisViewport
- Returns:
- the
Color
of the current pixel at the givenViewport
coordinates
-
setPixelVP
public void setPixelVP(int x, int y, Color c)
- Parameters:
x
- horizontal coordinate within thisViewport
y
- vertical coordinate within thisViewport
c
-Color
for the pixel at the givenViewport
coordinates
-
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 thisViewport
y
- vertical coordinate within thisViewport
c
- combined RGB value for the pixel at the givenViewport
coordinates
-
convertVP2FB
public FrameBuffer convertVP2FB()
Create a newFrameBuffer
containing the pixel data from thisViewport
rectangle.- Returns:
FrameBuffer
object holding pixel data from thisViewport
-
dumpVP2File
public void dumpVP2File(String filename)
Write thisViewport
to the specified PPM file.- Parameters:
filename
- name of PPM image file to holdViewport
data
-
dumpVP2File
public void dumpVP2File(String filename, String formatName)
Write thisViewport
to the specified image file using the specified file format.- Parameters:
filename
- name of the image file to holdViewport
dataformatName
- informal name of the image format
-
vpTestPattern
public void vpTestPattern()
A simple test of theViewport
.It fills the viewport with a test pattern.
-
-