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
|
private int[] ids = new int[3];
int num_vertices_all=12;
public void init(GLDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
gl.glEnable(GL.GL_DOUBLEBUFFER);
gl.glEnable(GL.GL_DEPTH);
int status = 0;
//creation des points
float []colors = new float[33];
double []pts = new double[33];
int []indices = new int[20];
num_vertices_all=4;
pts[0] = 0; pts[1] = 0; pts[2] = 0;
pts[3] = 0 ; pts[4] = 10;pts[5] = 0;
pts[6] = 0 ; pts[7] = 20;pts[8] = 0;
pts[9] = 10 ; pts[10] = 0;pts[11] = 0;
pts[12] = 10 ; pts[13] = 10;pts[14] = 0;
pts[15] = 10 ; pts[16] = 20;pts[17] = 0;
pts[18] = 20 ; pts[19] = 0;pts[20] = 0;
pts[21] = 20 ; pts[22] = 10;pts[23] = 0;
pts[24] = 30 ; pts[25] = 20;pts[26] = 0;
pts[27] = 30 ; pts[28] = 20;pts[29] = 0;
pts[30] = 30 ; pts[31] = 20;pts[32] = 0;
colors[0] = 0; colors[1] = 1; colors[2] = 0;
colors[3] = 0; colors[4] = 1; colors[5] = 0;
colors[6] = 0; colors[7] = 1; colors[8] = 0;
colors[9] = 0; colors[10] = 0; colors[11] = 1;
colors[12] = 0; colors[13] = 0; colors[14] = 1;
colors[15] = 0; colors[16] = 0; colors[17] = 1;
colors[18] = 0; colors[19] = 1; colors[10] = 1;
colors[21] = 0; colors[22] = 1; colors[23] = 1;
colors[24] = 0; colors[25] = 0; colors[26] = 1;
colors[27] = 1; colors[28] = 0; colors[29] = 1;
colors[30] = 1; colors[31] = 0; colors[32] = 1;
indices[0] = 0; indices[1] =3;
indices[2] = 1; indices[3] =4;
indices[4] = 2; indices[5] =5;
indices[6] = 5; indices[7] =8;
indices[8] = 4; indices[9] =7;
indices[10] = 3; indices[11] =6;
indices[12] = 6; indices[13] =9;
indices[14] = 6; indices[15] =9;
indices[16] = 7; indices[17] =10;
indices[18] = 8; indices[19] =11;
int nbPts = 12;
num_vertices_all=20;
IntBuffer indicesBuffer = BufferUtils.newIntBuffer(num_vertices_all);
FloatBuffer colorsBuffer = BufferUtils.newFloatBuffer(nbPts*3);
DoubleBuffer ptsBuffer = BufferUtils.newDoubleBuffer(nbPts*3);
indicesBuffer.put(indices);
colorsBuffer.put(colors);
ptsBuffer.put(pts);
gl.glGenBuffersARB( 3, ids );
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, ids[0] ); // Bind The Buffer
gl.glBufferDataARB( GL.GL_ARRAY_BUFFER_ARB,
nbPts*3*BufferUtils.SIZEOF_DOUBLE,
ptsBuffer, GL.GL_STATIC_DRAW_ARB );
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, ids[1] ); // Bind The Buffer
gl.glBufferDataARB( GL.GL_ARRAY_BUFFER_ARB,
nbPts*3*BufferUtils.SIZEOF_FLOAT,
colorsBuffer, GL.GL_STATIC_DRAW_ARB );
gl.glBindBufferARB(GL.GL_ARRAY_BUFFER_ARB, ids[2]); // Bind The Buffer
gl.glBufferDataARB(GL.GL_ARRAY_BUFFER_ARB,
num_vertices_all * BufferUtils.SIZEOF_INT,
indicesBuffer, GL.GL_STATIC_DRAW_ARB);
//lecture des infos sur la carte
System.err.println("GL_VENDOR: " + gl.glGetString(GL.GL_VENDOR));
System.err.println("GL_RENDERER: " + gl.glGetString(GL.GL_RENDERER));
System.err.println("GL_VERSION: " + gl.glGetString(GL.GL_VERSION));
canvas.setAutoSwapBufferMode(false);
}
*********************************************
public boolean display(GLDrawable drawable) {
GL gl = drawable.getGL();
GLU glu = drawable.getGLU();
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
float trans = 0;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(30, this.width / this.height, 1, 9000000);
gl.glViewport(0, 0, width, height);
gl.glViewport(0, 0, width, height);
gl.glClearColor(1f, 0, 0, 0);
gl.glDisable(GL.GL_LIGHTING);
gl.glDisable(GL.GL_BLEND);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glEnable(gl.GL_CULL_FACE);
gl.glEnable(GL.GL_DEPTH);
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glColor3f(0,1,0);
gl.glEnableClientState (GL.GL_VERTEX_ARRAY);
gl.glEnableClientState (GL.GL_COLOR_ARRAY);
gl.glEnableClientState (GL.GL_INDEX_ARRAY);
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, ids[0] );
gl.glVertexPointer( 3, GL.GL_DOUBLE, 0, (Buffer) null );
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, ids[1] );
gl.glColorPointer( 3, GL.GL_FLOAT, 0, (Buffer) null );
gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, ids[2] );
gl.glIndexPointer(2, GL.GL_INT, (Buffer) null );
gl.glDrawArrays (GL.GL_TRIANGLE_STRIP, 0, num_vertices_all);
gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL.GL_COLOR_ARRAY);
gl.glDisableClientState(GL.GL_INDEX_ARRAY);
gl.glFlush ();
return true;
}
********************************************* |
Partager