
Drawing a POINT Problem on OpenGL Java:
(…..imports as before)
public class Code extends JFrame implements GLEventListener
{ private int renderingProgram;
private int vao[ ] = new int[1];
public Code() { (…..constructor as before) }
public void display(GLAutoDrawable drawable)
{ GL4 gl = (GL4) GLContext.getCurrentGL();
gl.glUseProgram(renderingProgram);
gl.glDrawArrays(GL_POINTS, 0, 1);
}
public void init(GLAutoDrawable drawable)
{ GL4 gl = (GL4) GLContext.getCurrentGL();
renderingProgram = createShaderProgram();
gl.glGenVertexArrays(vao.length, vao, 0);
gl.glBindVertexArray(vao[0]);
}
private int createShaderProgram()
{ GL4 gl = (GL4) GLContext.getCurrentGL();
String vshaderSource[ ] =
{ "#version 430 \n",
"void main(void) \n",
"{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); } \n",
};
String fshaderSource[ ] =
{ "#version 430 \n",
"out vec4 color; \n",
"void main(void) \n",
"{ color = vec4(0.0, 0.0, 1.0, 1.0); } \n",
};
int vShader = gl.glCreateShader(GL_VERTEX_SHADER);
gl.glShaderSource(vShader, 3, vshaderSource, null, 0); // 3 is the count of lines of source code
gl.glCompileShader(vShader);
int fShader=gl.glCreateShader(GL_FRAGMENT_SHADER);
gl.glShaderSource(fShader, 4, fshaderSource, null, 0); // 4 is the count of lines of source code
gl.glCompileShader(fShader);
int vfProgram = gl.glCreateProgram();
gl.glAttachShader(vfProgram, vShader);
gl.glAttachShader(vfProgram, fShader);
gl.glLinkProgram(vfProgram);
gl.glDeleteShader(vShader);
gl.glDeleteShader(fShader);
return vfProgram;
}
. . . main(), reshape(), and dispose() as before
/* fragshader coding */
#version 430
out vec4 color;
void main(void)
{
if (gl_FragCoord.x < 295) color = vec4(1.0, 0.0, 0.0, 1.0);
else if(gl_FragCoord.x > 295 && gl_FragCoord.x < 310) color = vec4(1.0, 0.0, 1.0, 1.0);
else color = vec4(0.0, 0.0, 1.0, 1.0);
}
/* vertshader coding */
#version 430
uniform float offset;
void main(void)
{
if (gl_VertexID == 0) gl_Position = vec4( 0.25 + offset, -0.25, 0.0, 1.0);
else if (gl_VertexID == 1) gl_Position = vec4(-0.25 + offset, -0.25, 0.0, 1.0);
else gl_Position = vec4( 0.25 + offset, 0.25, 0.0, 1.0);
}
How answer below question with explanations & picture:
1. Modify above Java OpenGL
2. Modify above Java OpenGL program so that the drawn rectangle (not point) will grow and shrink in a cycle (try to move the rectangle in x-axis)?

Step by stepSolved in 4 steps

- Q1: Write the Java code corresponding to the following UML diagram. The class School implements the interface Building. The method computeArea returns the area of the building as width * length. After that, add a testing class with a main method which defines an arrayList that contains three objects. From the main method, print the area of all the three objects. Building > + computeArea() : double + toString() : String School classroomNum: int width: double - length: double + School(classroomNum: int, width: double, length: double) + computeArea() : double + toString() : Stringarrow_forwardImplement move the following way. public int[] walk(int... stepCounts) { // Implement the logic for walking the players returnnewint[0]; } public class WalkingBoardWithPlayers extends WalkingBoard{ privatePlayer[] players; privateintround; publicstaticfinalintSCORE_EACH_STEP=13; publicWalkingBoardWithPlayers(int[][] board, intplayerCount) { super(board); initPlayers(playerCount); } publicWalkingBoardWithPlayers(intsize, intplayerCount) { super(size); initPlayers(playerCount); } privatevoidinitPlayers(intplayerCount) { if(playerCount <2){ thrownewIllegalArgumentException("Player count must be at least 2"); } else { this.players=newPlayer[playerCount]; this.players[0] =newMadlyRotatingBuccaneer(); for (inti=1; i < playerCount; i++) { this.players[i] =newPlayer(); } } } package walking.game.player; import walking.game.util.Direction; public class Player{ privateintscore; protectedDirectiondirection=Direction.UP; publicPlayer() {} publicintgetScore() { return score; }…arrow_forwardJava Computer Programming. Each robot: - Has a name (attribute name: string) - Has a position: given by the integer attributes x and y. - Has a direction: given by the direction attribute that takes one of the values "North", "East", "South" or "West". The name, position and direction of a robot are given to it at the moment of its creation - Can advance one step forward: with method without parameter advance () - Can turn right 90 ° to change direction (if its direction was "North" it becomes "East", if it was "East" it becomes "South", etc.): with the method without parameter right(). Robots cannot turn left. - Can display its detail with the method detail() Detail: name, position, and current direction.arrow_forward
- What are the Javadoc comments for each class? I am strugglingarrow_forwardConsider the GameOfLife class public class GameOfLife { private BooleanProperty[][] cells; public GameOfLife() { cells = new BooleanProperty[10][10]; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { cells[x][y] = new SimpleBooleanProperty(); public void ensureAlive(int x, int y) { cells[x][y].set(true); public void ensureDead(int x, int y) { cells[x][y]•set(false); public boolean isAlive(int x, int y) { return cells[x][y]•get(); } a. Identify one code smell in this program. b. Identify and explain the most pertinent (problematic) design smell in this program.arrow_forwardimport javax.swing.*; import java.util.ArrayList; import java.util.Collections; import java.util.Random; import java.awt.*; import java.awt.event.*; public class memory extends JFrame implements ActionListener { private JButton[] cards; private ImageIcon[] icons; private int[] iconIDs; private JButton firstButton; private ImageIcon firstIcon; private int numMatches; public memory() { setTitle("Memory Matching Game"); setSize(800, 600); setLayout(new BorderLayout()); JPanel boardPanel = new JPanel(new GridLayout(4, 4)); add(boardPanel, BorderLayout.CENTER); icons = new ImageIcon[8]; for (int i = 1; i <= 8; i++) { icons[i-1] = new ImageIcon("image" + i + ".png"); } iconIDs = new int[16]; for (int i = 0; i < 8; i++) { iconIDs[2*i] = i; iconIDs[2*i+1] = i; } Random rand = new Random(); for (int i = 0; i < 16;…arrow_forward
- 1. How to modify below Java OpenGL to add animation that causes the drawn point to grow and shrink, in a cycle. Hint: use the glPointSize() function, with a variable as the parameter.2. How to modify below Java OpenGL the result from no 1, so that the drawn rectangle (not point) will grow and shrink in a cycle. Possible try to move the rectangle in x-axis. import javax.swing.*;import static com.jogamp.opengl.GL4.*;import com.jogamp.opengl.*;import com.jogamp.opengl.awt.GLCanvas; public class Program2_2 extends JFrame implements GLEventListener { private GLCanvas myCanvas; private int renderingProgram; private int vao[] = new int[1]; public Program2_2() { setTitle("Chapter2 - Program2"); setSize(600, 400); setLocation(200, 200); myCanvas = new GLCanvas(); myCanvas.addGLEventListener(this); this.add(myCanvas); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public void…arrow_forwardBelow is example Shader Java OpenGL coding: Shader Coding: fragShader.glsl #version 430in vec4 varyingColor;out vec4 color;uniform mat4 mv_matrix;uniform mat4 p_matrix;void main(void){ color = varyingColor;}vertShader.glsl #version 430layout (location=0) in vec3 position;uniform mat4 mv_matrix;uniform mat4 p_matrix;out vec4 varyingColor; void main(void){ gl_Position = p_matrix * mv_matrix * vec4(position,1.0); varyingColor = vec4(position,1.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);} Questions : 1. How to make Java OpenGL coding to add sphere 3D shape. Be sure to properly specify the number of vertices in the glDrawArrays() command ? answer with coding (plug & play) 2. How to make Java OpenGL coding from answer No.1, so that the additional 3D shape rotates on its axis (just like the earth’s rotation, but we may choose which axis to rotate on, x, y, or z-axis) ? answer with coding (plug & play)arrow_forwardJava language Use arrays in creating your class. Stack Interface (LIFO) void push(Object) Object pop() String toString() boolean isEmpty() boolean equals(Object) getIndexOf get remove private static void arrayListTests() { System.out.println("ArrayList Tests"); // todo: make more tests here ArrayList a = new ArrayList(); System.out.println("Check empty array isEmpty:" + a.isEmpty()); a.insert('B', 0); a.insert('a', 0); a.insert('t', 1); System.out.println("Check non-empty array isEmpty:" + a.isEmpty()); System.out.println(a.toString()); while (a.isEmpty() == false) { System.out.println(a.remove(0)); } // Fill over initial capacity and check that it grows for (int i = 0; i < 110; i++) { a.append(new Integer(i)); } System.out.println("Size of array after 110 adds: "+ a.size()); System.out.println("Value of last element: "+ a.get(a.size()-1)); System.out.println("Insert past end of list"); a.insert('z', 200); System.out.println("Insert negative index"); a.insert('z', -3);…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





