-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainKlass.java
More file actions
132 lines (95 loc) · 3.76 KB
/
Copy pathMainKlass.java
File metadata and controls
132 lines (95 loc) · 3.76 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package opengl_java_awt;
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
//import javax.media.opengl;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;
import javax.swing.JFrame;
/**
*
* @author shikami
*/
public class MainKlass implements GLEventListener{
GL2 gl;
public MainKlass(){
}
public static void main(String args[]){
//Version de OpenGL a utilizar
final GLProfile profile = GLProfile.get(GLProfile.GL2);
//Capacidades disponibles del perfil
GLCapabilities capabilities = new GLCapabilities(profile);
final GLCanvas glcanvas = new GLCanvas(capabilities);
MainKlass mk = new MainKlass();
glcanvas.addGLEventListener(mk);
glcanvas.setSize(400, 400);
//final Frame frame = new Frame("Basic Frame");
final JFrame frame = new JFrame("Basic Frame");
//final GLJPanel frame = new GLJPanel();
frame.add(glcanvas);
frame.setSize(640, 480);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//it is called by the object of GLAUTODRAWABLE interface inmediately after the OpenGL context
//is initialized
@Override
public void init(GLAutoDrawable glad) {
//Cambia color del fondo
gl = glad.getGL().getGL2();
gl.glClearColor(1f,1f,1f,1f);
}
//This method signals the listener to permorfm the release of all OpenGl resources per each GLContext, such as memory
//buffers and GLSL programs
@Override
public void dispose(GLAutoDrawable glad) {
}
//It is called by the object of GLAutoDrawable interface to initiate Opengl rendering by the client.
//This method contains the login used to draw graphical elements using OpenGL API.
@Override
public void display(GLAutoDrawable glad) {
gl = glad.getGL().getGL2();
gl.glBegin(GL2.GL_LINES);
gl.glColor3d(0,0,0);
//base cuadrada
gl.glVertex3f(-.5f,.12f,0);
gl.glVertex3f(-.5f,-.25f,0);
gl.glVertex3f(.5f,.12f,0);
gl.glVertex3f(.5f,-.25f,0);
gl.glVertex3f(-.5f,-.25f,0);
gl.glVertex3f(.5f,-.25f,0);
gl.glVertex3f(-.5f,.12f,0);
gl.glVertex3f(.5f,.12f,0);
//cabina
gl.glVertex3f(-.3f,.12f,0);
gl.glVertex3f(-.3f,.3f,0);
gl.glVertex3f(.3f,.12f,0);
gl.glVertex3f(.3f,.3f,0);
gl.glVertex3f(-.3f,.3f,0);
gl.glVertex3f(.3f,.3f,0);
drawCircle(gl,-.25f,-.25f,180);
drawCircle(gl,.25f,-.25f,180);
gl.glEnd();
}
//It is called by the object of GLAutoDrawable interface during the first repaint afeter the component has been resized.
@Override
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
public void drawCircle(GL2 gl,float xc,float yc,int gi){
for(double alpha = gi; alpha<360;alpha+=5){
float dx = (float) ((.15)*Math.cos(alpha));
float dy = (float) ((.15)*Math.sin(alpha));
gl.glVertex3f(xc+dx,yc+dy,0);
dx = (float) ((.15)*Math.cos(alpha+1));
dy = (float) ((.15)*Math.sin(alpha+1));
gl.glVertex3f(xc+dx,yc+dy,0);
}
}
}