PDA

View Full Version : vertex array from MySQL database



airtruk
02-23-2011, 03:37 AM
I'm trying to generate vertex arrays from point data that lives in a MySQL database.
I can read out the values without a problem and create an array with float point values representing the xyz coordinates of a simple triangle.
When I'm going to pass that array to glVertexPointer it doesn't seem to display anything. Before I start posting any code I thought I might ask if there is anyone out there that has retrieved the coordinates from a database and then used them in vertex arrays in OpenGL. The whole thing is written in C with OpenGL 1.1 and I need to keep it that way.

Any help is welcome!

ravage
02-23-2011, 06:56 AM
You shouldn't have to feed the array into the glVertexPointer. Actually I thought you weren't able to use that function in webgl but instead glVertexAttribPointer.

here's an example:


var tri_buffer;
function initBuffers()
{
var vertices = [ 0.0, 1.0, 0.0,
-1.0, -1.0, 0.0,
1.0, -1.0, 0.0];


tri_buffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, tri_buffer);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
gl.bindBuffer(gl.ARRAY_BUFFER, null);

tri_buffer.itemSize = 3;
tri_buffer.numItems = 3;

alert("initBuffers Complete!");
alert(gl.getError());

}

then when drawing:


gl.useProgram(shaderProgram);
gl.bindBuffer(gl.ARRAY_BUFFER, tri_buffer);
gl.vertexAttribPointer(shaderProgram.vertexpositio n, tri_buffer.itemSize/*num of components*/, gl.FLOAT, false, 0, 0);

gl.uniformMatrix4fv(shaderProgram.pMatrix, false, new Float32Array(pMatrix.flatten()));
gl.uniformMatrix4fv(shaderProgram.mvMatrix, false, new Float32Array(mvMatrix.flatten()));

gl.drawArrays(gl.TRIANGLES, 0, tri_buffer.numItems/*num of vertices*/);


gl.bindBuffer(gl.ARRAY_BUFFER, null);
gl.useProgram(null);

mbentrup
02-23-2011, 08:02 AM
Did you enable the vertex array with "glEnableClientState(GL_VERTEX_ARRAY);" ?

airtruk
02-23-2011, 07:44 PM
I managed to get it to work. Here is the code

while((row = mysql_fetch_row(result)) != NULL){
vertices[verticesCount] = (GLfloat) atof(row[0]);
verticesCount++;
vertices[verticesCount] = (GLfloat) atof(row[1]);
verticesCount++;
vertices[verticesCount] = (GLfloat) atof(row[2]);
verticesCount++;
}

this assumes that each row returned from the database has x,y and z as a column, hence the 3 row[] assignments to the vertices array.