Dynamically allocating a 3-D GLfloat array.

111 views
Skip to first unread message

komplikaded

unread,
Jul 17, 2010, 3:46:48 PM7/17/10
to PSUComputerGraphics
I'm trying to dynamically-allocate a 3-dimensional GLfloat array in C+
+. The OpenGL library is working...I was able to render a few things
already.

Here's the code snippet:
GLfloat ***controlPoints = new GLfloat**[1];

//Set up the array of control points.
for (j = 0; j < 6; ++j)
{
**controlPoints[j] = new GLfloat*[6];
for (i = 0; i < 3; ++i)
*controlPoints[j][i] = new GLfloat[3];
}

For some reason I get the errors:
main.cpp:101: error: cannot convert ‘GLfloat**’ to ‘float’ in
assignment
main.cpp:103: error: cannot convert ‘GLfloat*’ to ‘float’ in
assignment

i and j are ints initialized to 0. Any ideas? Thanks.

Karla Fant

unread,
Jul 17, 2010, 6:38:06 PM7/17/10
to psucomput...@googlegroups.com
Here is your code:

GLfloat ***controlPoints = new GLfloat**[1];

//Set up the array of control points.
for (j = 0; j < 6; ++j)
{
**controlPoints[j] = new GLfloat*[6];
for (i = 0; i < 3; ++i)
*controlPoints[j][i] = new GLfloat[3];
}

Notice you cannot dereference when you haven't allocated - which means the
data types above are not correct in all places. Also remember that the []
implicitly dereferences. So the *'s in front on controlPoints are not always
necessary:

controlPoints[j] = new GLfloat*[6]; //controlPoints[j] is a pointer to a
pointer to a GLfloat

controlPoints[j][i] = new GLfloat[3]; //conotrolPoints[j][i] is a pointer to
a GLfloat

--
You received this message because you are subscribed to the Google Groups
"PSUComputerGraphics" group.
To post to this group, send email to psucomput...@googlegroups.com.
To unsubscribe from this group, send email to
psucomputergrap...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/psucomputergraphics?hl=en.

Message has been deleted

Karla Fant

unread,
Jul 21, 2010, 10:50:53 AM7/21/10
to psucomput...@googlegroups.com
I would suggest making sure the memory is allocated correctly.

-----Original Message-----
From: psucomput...@googlegroups.com
[mailto:psucomput...@googlegroups.com] On Behalf Of komplikaded
Sent: Tuesday, July 20, 2010 4:33 PM
To: PSUComputerGraphics
Subject: Re: [PSUComputerGraphics] Dynamically allocating a 3-D GLfloat
array.

Thanks. I worked past that hurdle. Now I'm getting a core dump when I try
to map the points in OpenGL. I already put cout statements as I'm drawing
the points, so I know that OpenGL drew the points (unless there's some way
OpenGL gives an error if I pass in incorrect arguments? I'm passing in
pointers instead of a static array). Any idea why glMap2f would give a core
dump?

glMap2f(GL_MAP2_VERTEX_3,
0.0f,
10.0f,
3,
3,
0.0f,
10.0f,
9.0f,
3.0f,
&controlPoints[0][0][0]
);

Reply all
Reply to author
Forward
0 new messages