Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Este tutorial lo realice con el propsito de ayudar a otros en cuanto a la conexin y prueba de los programas en opengl y netbeans.
lwjgl
Das doble clic a esta carpeta recin cambiada el nombre das clic a la carpeta doc y en ella ay un archivo llamada readme a esta dale doble clic.
Esto se hace para saber que el programa este funcionando correctamente. brelo con un bloq de notas.
Enseguida te aparece la pantalla negra el objetivo es acesar a la carpeta donde se encuentra el archivo de prueba que esta dentro de la carpeta lwjgl para ello sigue estos pasos:
Enseguida nos vamos al archivo que abrimos anterior mete llamado readme de la carpeta doc y pegamos este escrito:
El siguiente paso es irnos de nuevo a nuestro archivo readme y copiar este cdigo
Y damos finish
nota importante: Es necesario que en este momento pongas en set layout a este panel que creamos
Y asi se mostrar
A este panel es necesario ponerle nombre para ello vete a inspector selecciona el panel da clic derecho.
En este momento ya tiene nombre nuestro panel que agregamos enseguida tenemos que agregarle un toggle botn
Ahora es momento de irnos a nuestro constructor del Frame ventana y damos clic en sourse.
private Claseopengl pnLog1; /** Creates new form Ventana */ public Ventana() { initComponents();
try{
Tutorial: Pedro Lpez Salazar Instituto tecnolgico Superior de Zapopan Pgina 21
pnLog1.start();
Ahora que ya terminamos con el programa debemos de crear una clase y lo meteremos dentro de nuestro paquete. Sigamos estos pasos:
package miopengl;
// Angle For The Triangle ( NEW ) // Angle For The Quad ( NEW )
private void ejes() { GL11.glBegin(GL11.GL_LINES); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glVertex3f(0.0f, 0.0f, 0.0f); GL11.glVertex3f(10.0f, 0.0f, 0.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f); GL11.glVertex3f(0.0f, 0.0f, 0.0f); GL11.glVertex3f(0.0f, 0.0f, 10.0f); GL11.glEnd(); }
private void triangulo() { GL11.glPushMatrix(); //GL11.glLoadIdentity(); GL11.glTranslatef(-1.5f,0.0f,-6.0f); GL11.glRotatef(rtri,0.0f,1.0f,0.0f); GL11.glBegin(GL11.GL_TRIANGLES); GL11.glColor3f(1.0f,0.0f,0.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glColor3f(0.0f,1.0f,0.0f); GL11.glVertex3f(-1.0f,-1.0f, 1.0f); // Red // Top Of Triangle (Front) // Green // Left Of Triangle (Front) // Move Left 1.5 Units And Into The Screen 6.0 // Rotate The Triangle On The Y axis ( NEW ) // Drawing Using Triangles
private void cubo() { GL11.glPushMatrix(); GL11.glTranslatef(1.5f,0.0f,-7.0f); GL11.glRotatef(rquad,1.0f,1.0f,1.0f); // Move Right 1.5 Units And Into The Screen 6.0 // Rotate The Quad On The X axis ( NEW )
/** * Override this to do initialising of the context. * It will be called once from paint(), immediately after * the context is created and made current. */ @Override protected void initGL() { GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background GL11.glClearDepth(1.0); // Depth Buffer Setup GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window GLU.gluPerspective( 45.0f, (float) this.getWidth() / (float) this.getHeight(),
GL11.glLoadIdentity();
GL11.glTranslatef(xTras, yTras, zTras); GL11.glRotatef(xRot, 1.0f, 0.0f, 0.0f); GL11.glRotatef(yRot, 0.0f, 1.0f, 0.0f); GL11.glRotatef(zRot, 0.0f, 0.0f, 1.0f);
public void run() { Thread me = Thread.currentThread(); while (thread == me) { repaint(); } thread = null; }
Y damos clic en ok en mi caso como ya lo tengo agregado por eso me salio de color rojo el mensaje.
Lo que tenemos que hacer en seguida es agregar los jar a nuestra librera recin creada llamada lwjgl:
Y asi aparecern
Damos clic derecho a nuestro proyecto elegimos en el men contextual la opcin propiedades
-Djava.library.path=
-Djava.library.path=C:\Users\pedro\Documents\lwjgl\native\windows
Cdigo de la ventana: /* * To change this template, choose Tools | Templates * and open the template in the editor. */
package miopengl; Tutorial: Pedro Lpez Salazar Instituto tecnolgico Superior de Zapopan Pgina 49
/** * * @author pedro */ public class Ventana extends javax.swing.JFrame { private Claseopengl pnLog1; /** Creates new form Ventana */ public Ventana() { initComponents();
/** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout pnHerramientasLayout = new javax.swing.GroupLayout(pnHerramientas); pnHerramientas.setLayout(pnHerramientasLayout); pnHerramientasLayout.setHorizontalGroup( pnHerramientasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnHerramientasLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnAnimar)) ); Tutorial: Pedro Lpez Salazar Instituto tecnolgico Superior de Zapopan Pgina 51
getContentPane().add(pnHerramientas, java.awt.BorderLayout.LINE_START);
/** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Ventana().setVisible(true); } }); } Tutorial: Pedro Lpez Salazar Instituto tecnolgico Superior de Zapopan Pgina 52
// Variables declaration - do not modify private javax.swing.JToggleButton btnAnimar; private javax.swing.JPanel pnHerramientas; // End of variables declaration
Cdigo de la clase
package miopengl;
// Angle For The Triangle ( NEW ) // Angle For The Quad ( NEW )
private void ejes() { GL11.glBegin(GL11.GL_LINES); GL11.glColor3f(1.0f, 0.0f, 0.0f); GL11.glVertex3f(0.0f, 0.0f, 0.0f); GL11.glVertex3f(10.0f, 0.0f, 0.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f); GL11.glVertex3f(0.0f, 0.0f, 0.0f); GL11.glVertex3f(0.0f, 0.0f, 10.0f); GL11.glEnd();
private void triangulo() { GL11.glPushMatrix(); //GL11.glLoadIdentity(); GL11.glTranslatef(-1.5f,0.0f,-6.0f); GL11.glRotatef(rtri,0.0f,1.0f,0.0f); GL11.glBegin(GL11.GL_TRIANGLES); GL11.glColor3f(1.0f,0.0f,0.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glColor3f(0.0f,1.0f,0.0f); GL11.glVertex3f(-1.0f,-1.0f, 1.0f); GL11.glColor3f(0.0f,0.0f,1.0f); GL11.glVertex3f( 1.0f,-1.0f, 1.0f); GL11.glColor3f(1.0f,0.0f,0.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glColor3f(0.0f,0.0f,1.0f); GL11.glVertex3f( 1.0f,-1.0f, 1.0f); GL11.glColor3f(0.0f,1.0f,0.0f); GL11.glVertex3f( 1.0f,-1.0f, -1.0f); GL11.glColor3f(1.0f,0.0f,0.0f); GL11.glVertex3f( 0.0f, 1.0f, 0.0f); GL11.glColor3f(0.0f,1.0f,0.0f); GL11.glVertex3f( 1.0f,-1.0f, -1.0f); GL11.glColor3f(0.0f,0.0f,1.0f); GL11.glVertex3f(-1.0f,-1.0f, -1.0f); GL11.glColor3f(1.0f,0.0f,0.0f); // Red // Top Of Triangle (Front) // Green // Left Of Triangle (Front) // Blue // Right Of Triangle (Front) // Red // Top Of Triangle (Right) // Blue // Left Of Triangle (Right) // Green // Right Of Triangle (Right) // Red // Top Of Triangle (Back) // Green // Left Of Triangle (Back) // Blue // Right Of Triangle (Back) // Red // Move Left 1.5 Units And Into The Screen 6.0 // Rotate The Triangle On The Y axis ( NEW ) // Drawing Using Triangles
private void cubo() { GL11.glPushMatrix(); GL11.glTranslatef(1.5f,0.0f,-7.0f); GL11.glRotatef(rquad,1.0f,1.0f,1.0f); GL11.glColor3f(0.5f,0.5f,1.0f); GL11.glBegin(GL11.GL_QUADS); GL11.glColor3f(0.0f,1.0f,0.0f); GL11.glVertex3f( 1.0f, 1.0f,-1.0f); GL11.glVertex3f(-1.0f, 1.0f,-1.0f); GL11.glVertex3f(-1.0f, 1.0f, 1.0f); GL11.glVertex3f( 1.0f, 1.0f, 1.0f); GL11.glColor3f(1.0f,0.5f,0.0f); GL11.glVertex3f( 1.0f,-1.0f, 1.0f); GL11.glVertex3f(-1.0f,-1.0f, 1.0f); GL11.glVertex3f(-1.0f,-1.0f,-1.0f); GL11.glVertex3f( 1.0f,-1.0f,-1.0f); GL11.glColor3f(1.0f,0.0f,0.0f); // Move Right 1.5 Units And Into The Screen 6.0 // Rotate The Quad On The X axis ( NEW ) // Set The Color To Blue One Time Only // Draw A Quad // Set The Color To Green // Top Right Of The Quad (Top) // Top Left Of The Quad (Top) // Bottom Left Of The Quad (Top) // Bottom Right Of The Quad (Top) // Set The Color To Orange // Top Right Of The Quad (Bottom) // Top Left Of The Quad (Bottom) // Bottom Left Of The Quad (Bottom) // Bottom Right Of The Quad (Bottom) // Set The Color To Red
/** * Override this to do initialising of the context. * It will be called once from paint(), immediately after
GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix GL11.glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window GLU.gluPerspective( 45.0f, (float) this.getWidth() / (float) this.getHeight(), 0.1f, 100.0f); GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
// Clear
GL11.glLoadIdentity();
GL11.glTranslatef(xTras, yTras, zTras); GL11.glRotatef(xRot, 1.0f, 0.0f, 0.0f); GL11.glRotatef(yRot, 0.0f, 1.0f, 0.0f); GL11.glRotatef(zRot, 0.0f, 0.0f, 1.0f);
public void start() { thread = new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); Tutorial: Pedro Lpez Salazar Instituto tecnolgico Superior de Zapopan Pgina 59
public void run() { Thread me = Thread.currentThread(); while (thread == me) { repaint(); } thread = null; }