Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Dyn. 2 dim float array not same as float[4][4]??


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 HellRiZZer   Members   -  Reputation: 308

Like
Likes
Like

Posted 18 November 2001 - 02:02 PM

I was recently trying to make a 2 dim array for use with glMap2f(OpenGL) and making all its values same as the array float[4][4][3]. E.g I made typedef float glVertex3fv[3]; Then, I do: glVertex3fv **Grid; Then I allocate 2 dim array as 4x4 Grid = new glVertex3fv*[4]; for (int i=0;i<4;i++) Grid = new glVertex3fv[4]; And here I just assign all values of float[4][4][3] to Grid[x][y][0,1,2]. When I go to glMap2f and pass it not as &float[0][0](starting array value), but as (float *)&Grid[0][0], it draws some buggy things, not the patch I had with float[4][4][3].. Why? Someone help please? Thanks.

Sponsor:

#2 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 18 November 2001 - 06:53 PM

Ok... no, an array of arrays is not structurally equivalent to a 2D array (sorry if I pointed you in the wrong direction earlier).

float[4][4][3] is the same thing than float[48].

As others had said before, you will have to allocate it in one chunk and compute the indices yourself.


#3 Fruny   Moderators   -  Reputation: 1653

Like
Likes
Like

Posted 18 November 2001 - 06:59 PM

Oh, and by the way, glVertex3fv is a function name.
You are calling for trouble to define it as a type.

try that way

  
#include <vector>

typedef struct
{
float r, g, b;
} pixel_t;

typedef std::vector<pixel_t> grid_t;

.
.
.

grid_t Grid( rows * columns );

for( y = 0; y < rows; ++y ) // y outside to preserve locality of access

for( x = 0; x < columns; ++x )
{
Grid[x + columns * y].r = ...
Grid[x + columns * y].g = ...
Grid[x + columns * y].b = ...
}






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS