-
Notifications
You must be signed in to change notification settings - Fork 0
/
JOGL-2.java
91 lines (72 loc) · 2.43 KB
/
JOGL-2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.glu.GLU;
import java.io.File;
import java.io.FileNotFoundException;
import javax.swing.JFrame;
import java.util.Scanner;
public class Assignment2 implements GLEventListener{
private GLU glu;
@Override
public void display(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
File file = new File ("randomValues.txt");
try {
Scanner scan= new Scanner(file);
gl.glBegin(GL2.GL_POINTS);
while (scan.hasNext()) {
double x = scan.nextDouble();
double y = scan.nextDouble();
gl.glVertex2d(x,y);
}
gl.glEnd();
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
DDA(gl, 4,4,7,10);
}
@Override
public void dispose(GLAutoDrawable arg0) {
//method body
}
@Override
public void init(GLAutoDrawable gld) {
GL2 gl = gld.getGL().getGL2();
glu = new GLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glViewport(-100, -50, 50, 100);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluOrtho2D(-100.0, 100.0, -100.0, 100.0);
}
@Override
public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
// method body
}
public void DDA(GL2 gl, float x1, float y1, float x2, float y2) {
gl.glPointSize(3.0f);
gl.glColor3d(1, 0, 0);
//write your own code
}
public static void main(String[] args) {
//getting the capabilities object of GL2 profile
final GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);
// The canvas
final GLCanvas glcanvas = new GLCanvas(capabilities);
Assignment2 l = new Assignment2();
glcanvas.addGLEventListener(l);
glcanvas.setSize(400, 400);
//creating frame
final JFrame frame = new JFrame ("straight Line");
//adding canvas to frame
frame.getContentPane().add(glcanvas);
frame.setSize(frame.getContentPane().getPreferredSize());
frame.setVisible(true);
}//end of main
}//end of classimport javax.media.opengl.GL2;