Re: [Vala] How to bitwise math and implement a jagged array in Vala?



I tried your code as you suggested however that did not work. I guess the real question that I am asking here is has anyone successfully generated a Checker board type texture with OpenGL and Vala and displayed it on a cube or square. That is the code that I really need. It seems that because Vala does not supported "jagged" arrays that this is not possible or did I miss something in the reading somewhere?

Thanks
Tom

On 07/02/2013 01:09 PM, Evan Nemerson wrote:
On Tue, 2013-07-02 at 06:36 -0500, Thomas F Steinhauer wrote:
Dear members I am new here and I have a couple of questions and they are
are all centered around this piece of code I found online:

  1. /*  Create checkerboard texture  */
  2. #define checkImageWidth 64
  3. #define checkImageHeight 64
  4. static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
  5. static GLuint texName;
  6. void makeCheckImage(void)
  7. {
  8.     int i, j, c;
  9.
10.     for (i = 0; i < checkImageHeight; i++) {
11.        for (j = 0; j < checkImageWidth; j++) {
12.           c = ((((i&0x8)==0)^((j&0x8))==0))*255;
13.           checkImage[i][j][0] = (GLubyte) c;
14.           checkImage[i][j][1] = (GLubyte) c;
15.           checkImage[i][j][2] = (GLubyte) c;
16.           checkImage[i][j][3] = (GLubyte) 255;
17.        }
18.     }
19. }

1st, How can I do that same thing or equivalent from line #4 in Vala or
is it not possible?
GL.ubyte[] checkImage =
   new GL.ubyte[checkImageHeight,checkImageWidth,4];

See https://wiki.gnome.org/Vala/Tutorial#Arrays for more information.

2nd. When I try to run line #12 in Vala I get an error "Operation not
supported for types bool and bool. So is there a way to get Vala to
evaluate this expression correctly?
Simon already mentioned one possible solution.  However, if you want to
do it without branching, you can just cast to an integer type.
Something like this should do the trick:

c = (((GL.ubyte)((i&0x8)==0))^((GL.ubyte)((j&0x8)==0)))*255;


-Evan






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]