PDA

View Full Version : build indices array at runtime



airtruk
02-23-2011, 08:50 PM
This is a follow-on post from the "vertex array from MySQL database". This time I need to create an array for the indices of the vertices previously created so I can cycle through them in the actual OpenGL part of the code. Here is what I currently got and I have a feeling that I'm not converting the data types correctly. Any help is welcomed

indices = (GLubyte*)realloc(indices, 4*mysql_num_fields(result)); // this will create the correct array size
while ((row = mysql_fetch_row(result)) != NULL){
indices[indicesCount] = (GLubyte)(atoi(row[0]-1));
indicesCount++;
}

any idea how one can create an indices array on the fly at runtime and what datatypes one has to use if char-type is the starting point, since that is what the MySQL query will return.

airtruk
02-23-2011, 08:57 PM
found the error myself :)

the line:
indices[indicesCount] = (GLubyte)(atoi(row[0]-1));

should be:
indices[indicesCount] = (GLubyte)(atoi(row[0])-1);

--> first convert the result to an integer and then subtract one ;)