Results 1 to 4 of 4

Thread: vertex array from MySQL database

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    4

    vertex array from MySQL database

    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!

  2. #2
    Member Contributor
    Join Date
    Jan 2010
    Posts
    82

    Re: vertex array from MySQL database

    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);

  3. #3
    Senior Member Regular Contributor
    Join Date
    Mar 2015
    Posts
    256

    Re: vertex array from MySQL database

    Did you enable the vertex array with "glEnableClientState(GL_VERTEX_ARRAY);" ?

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2011
    Posts
    4

    Re: vertex array from MySQL database

    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.

Similar Threads

  1. Generate Indices array from Vertex array
    By VirtualMan in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-28-2013, 02:51 AM
  2. a big vertex array or a ser of small vertex array?
    By lovemort in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 09-05-2013, 12:42 PM
  3. One Vertex Array or Multiple Vertex Arrays ?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-24-2003, 09:16 AM
  4. Why no per-vertex material specification in vertex array?
    By MelvinEng in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-09-2001, 03:20 AM
  5. Mixing Vertex Array Range & 'normal' vertex arrays
    By MarcusL in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 04-23-2001, 09:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean