-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEjercicioTriangulo.java
More file actions
130 lines (84 loc) · 3.47 KB
/
Copy pathEjercicioTriangulo.java
File metadata and controls
130 lines (84 loc) · 3.47 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
/*
* 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
*/
//Cambiar las dimenciones del entorno
//GLFrustum::SetOrthographic(GLfloat xMin, GLfloat xMax, GLfloat yMin,
//GLfloat yMax, GLfloat zMin, GLfloat zMax);
//Cambiar la perspectiva
//GLFrustum::SetPerspective(float fFov, float fAspect, float fNear, float fFar);
//shaderManager.InitializeStockShaders();
public class EjercicioTriangulo implements GLEventListener{
GL2 gl;
public EjercicioTriangulo(){
}
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);
EjercicioTriangulo mk = new EjercicioTriangulo();
glcanvas.addGLEventListener(mk);
glcanvas.setSize(400, 400);
//final Frame frame = new Frame("Basic Frame");
final JFrame frame = new JFrame("Basic Frame ej4");
//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);
}
//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.glColor3d(1,1,1);
gl.glPushMatrix();
gl.glScalef(.5f, .5f, .5f);
//Dibuja ciculo relleno con lineas del centro a cada
//punto de la circuferencias
gl.glBegin(GL2.GL_TRIANGLES);
gl.glColor3f(1,0,0);
gl.glVertex3f(0f,0f,0f);
gl.glColor3f(0,1,0);
gl.glVertex3f(.50f,0f,0f);
gl.glColor3f(0,0,1);
gl.glVertex3f(.50f,.50f,0f);
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) {
}
}