-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCubo.java
More file actions
170 lines (125 loc) · 4.7 KB
/
Copy pathCubo.java
File metadata and controls
170 lines (125 loc) · 4.7 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
* 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 com.jogamp.opengl.util.FPSAnimator;
import javax.swing.JFrame;
/**
*
* @author shikami
*/
//shaderManager.InitializeStockShaders();
public class Cubo implements GLEventListener{
GL2 gl;
FPSAnimator fps;
public Cubo(){
}
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);
Cubo mk = new Cubo();
glcanvas.addGLEventListener(mk);
glcanvas.setSize(400, 400);
//final Frame frame = new Frame("Basic Frame");
final JFrame frame = new JFrame("Basic Frame rotacion");
//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(0,0,0,0);
// if(fps==null){
// fps = new FPSAnimator(glad,1);
// fps.start();
// }
}
//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) {
//Obtener GL
gl = glad.getGL().getGL2();
//Limpiar graficos
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glFlush();
// gl.glRotatef(45,-.5f,-0f,0f);
gl.glRotatef(-45,-.5f,-.5f,0f);
// gl.glRotatef(-45,0f,0f,-.5f);
//TRASERA
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f( .5f,1f,1f );
gl.glVertex3f( 0.5f, -0.5f, -0.5f );
gl.glVertex3f( -0.5f, -0.5f, -0.5f );
gl.glVertex3f( -0.5f, 0.5f, -0.5f );
gl.glVertex3f( 0.5f, 0.5f, -0.5f );
gl.glEnd();
//ABAJO verde
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f( 0f,1f,0f );
gl.glVertex3f( 0.5f, -0.5f, 0.5f );
gl.glVertex3f( -0.5f, -0.5f, 0.5f );
gl.glVertex3f( -0.5f, -0.5f, -0.5f );
gl.glVertex3f( 0.5f, -0.5f, -0.5f );
gl.glEnd();
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f( 1f,0f,1f );
gl.glVertex3f( -0.5f, 0.5f, 0.5f );
gl.glVertex3f( -0.5f, 0.5f, -0.5f );
gl.glVertex3f( -0.5f, -0.5f, -0.5f );
gl.glVertex3f( -0.5f, -0.5f, 0.5f );
gl.glEnd();
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f( .87f,.35f,.1f );
gl.glVertex3f( 0.5f, 0.5f, -0.5f );
gl.glVertex3f( 0.5f, 0.5f, 0.5f );
gl.glVertex3f( 0.5f, -0.5f, 0.5f );
gl.glVertex3f( 0.5f, -0.5f, -0.5f );
gl.glEnd();
//Arriba amarilla
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f(1f,1f,0f);
gl.glVertex3f(0.5f, 0.5f, -0.5f);
gl.glVertex3f( -0.5f, 0.5f, -0.5f);
gl.glVertex3f( -0.5f, 0.5f, 0.5f );
gl.glVertex3f( 0.5f, 0.5f, 0.50f );
gl.glEnd();
//FRONTAL
gl.glBegin(GL2.GL_POLYGON);
gl.glColor3f( 0f,0f,1f );
gl.glVertex3f( 0.5f, 0.5f, 0.5f );
gl.glVertex3f( -0.5f, 0.5f, 0.5f );
gl.glVertex3f( -0.5f, -0.5f, 0.5f );
gl.glVertex3f( 0.5f, -0.5f, 0.5f );
gl.glEnd();
// gl.glPopMatrix();
}
//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) {
}
}