-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIluminacion.java
More file actions
149 lines (99 loc) · 4.24 KB
/
Copy pathIluminacion.java
File metadata and controls
149 lines (99 loc) · 4.24 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
/*
* 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;
//tipos de luces
//gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, light_ambient, 0);
//gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, light_diffuse, 0);
//gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, light_specular, 0);
//gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, light_position, 0);
/**
*
* @author shikami
*/
public class Iluminacion implements GLEventListener{
GL2 gl;
public Iluminacion(){
}
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);
Iluminacion mk = new Iluminacion();
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(0f,0f,0f,1f);
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
gl.glEnable(GL2.GL_NORMALIZE);
float[] ambientLight = { 0f, 1f, 0.f,0f }; // weak RED ambient
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambientLight, 0);
// float parampos[] = {0f,.8f,1f,0};
// gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, parampos,0);
FPSAnimator anim = new FPSAnimator(glad ,160);
anim.start();
// gl.glViewport( 1, 0, 1, 1 );
//canvas scale
gl.glOrtho(-5, 5, -5, 5, -5, 5);
gl.glTranslatef(0,0,0); // inverse of camera's location
}
//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.glFlush();
// Clear the drawing area
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glColor3d(1,1,1);
//Dibujar Objeto
gl.glBegin(GL2.GL_POLYGON);
gl.glVertex3f(0.2f,.4f,0);
gl.glVertex3f(-0.2f,.4f,0);
gl.glVertex3f(-0.4f,0,0);
gl.glVertex3f(-0.2f,-.4f,0);
gl.glVertex3f(0.2f,-.4f,0);
gl.glVertex3f(0.4f,0,0);
gl.glEnd();
float parampos[] = {0f,0f,.1f,0};
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, parampos,0);
gl.glRotatef(2,0f,1f,0f);
}
//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) {
}
}