The following works, to draw a square:
float a[] = {
-1, 1, 0,
1, 1, 0,
-1,-1, 0,
1,1,0,
-1,-1,0,
1,-1,0,
};
glVertexPointer( 3, GL_FLOAT, 0, a );
glDrawArrays( GL_TRIANGLES, 0, 6 );
The following code has the same logic, but I have inserted an extra
float between each vertex. I tell opengl by setting the stride to be
sizeof(float). But the following make square scrambled.
float a[] = {
-1, 1, 0,
99,
1, 1, 0,
99,
-1,-1, 0,
99,
1,1,0,
99,
-1,-1,0,
99,
1,-1,0,
99,
};
glVertexPointer( 3, GL_FLOAT, sizeof(float), a );
glDrawArrays( GL_TRIANGLES, 0, 6 );
Thanks,
~S
|
|
0
|
|
|
|
Reply
|
sheam
|
5/18/2008 10:52:14 PM |
|
sheam wrote:
> The following works, to draw a square:
> float a[] = {
> -1, 1, 0,
> 1, 1, 0,
> -1,-1, 0,
> 1,1,0,
> -1,-1,0,
> 1,-1,0,
> };
> glVertexPointer( 3, GL_FLOAT, 0, a );
> glDrawArrays( GL_TRIANGLES, 0, 6 );
>
> The following code has the same logic, but I have inserted an extra
> float between each vertex. I tell opengl by setting the stride to be
> sizeof(float). But the following make square scrambled.
> float a[] = {
> -1, 1, 0,
> 99,
> 1, 1, 0,
> 99,
> -1,-1, 0,
> 99,
> 1,1,0,
> 99,
> -1,-1,0,
> 99,
> 1,-1,0,
> 99,
> };
> glVertexPointer( 3, GL_FLOAT, sizeof(float), a );
> glDrawArrays( GL_TRIANGLES, 0, 6 );
>
> Thanks,
> ~S
Ok, I figure it out. stride is described in man page as bytes between.
But it is actually the number of bytes from start to start of next.
i.e., sizeof(float)*4 worked.
~S
|
|
0
|
|
|
|
Reply
|
sheam
|
5/18/2008 10:54:40 PM
|
|
On May 18, 5:54=A0pm, sheam <she...@eastlink.ca> wrote:
> > The following code has the same logic, but I have inserted an extra
> > float between each vertex. =A0I tell opengl by setting the stride to be
> > sizeof(float). =A0But the following make square scrambled.
[...]
> Ok, I figure it out. =A0stride is described in man page as bytes between.
> =A0 But it is actually the number of bytes from start to start of next.
> i.e., sizeof(float)*4 worked.
It can also be 0 for tightly packed arrays:
stride Specifies the byte offset between consecutive
vertexes. If
stride is 0, the vertexes are understood to be
tightly packed
in the array. The initial value
is 0.
Since your second example isn't tightly packed, you needed to specify
the offset.
- Chris
|
|
0
|
|
|
|
Reply
|
crjjrc
|
5/19/2008 12:26:06 PM
|
|
|
2 Replies
174 Views
(page loaded in 0.039 seconds)
Similiar Articles: Why no std::back_insert_iterator::value_type? - comp.lang.c++ ...The following prints "void", which seems to be what the ... Doesn't need T parameter. template <class OutIter> OutIter ... is aware of the conversion and thus can safely ignore ... stack size exceeds current limit - comp.unix.solaris... available stack space ... trying to ignore the problem by trying to limit step ... We thought that SHMMAX kernel parameter is ... limit exceeds? ... some checking, it seems ... Neatest way to get the end pointer? - comp.lang.c... satisfactorily packaged my other tools, but this seems ... thing to be added to the list of "UB" that we ignore. ... using for(i=0;i<N;i++) my_array[i] = 42; to step ... Idea: Applesoft & BG music - comp.sys.apple2.programmerIt seems to me that wouldn't be a hard thing to figure ... (Ignore this entry. I didn't mean to change to subject ... EQ $8C00 DAC1LO .EQ $06 DAC522 PLAYBACK PARAMETERS ... Dos and don'ts in C++ unit testing? - comp.lang.c++.moderated ...This seems very intriguing, but I can't find any clues ... not the best example, but it makes it easier to step ... as reference, using examples in textbooks and parameter ... How to get envelope from AM signal without phase shift - comp.dsp ...From your description it seems like your I component is fed directly without low ... sensitive to most minute variations in initial conditions or environment parameters. improve strlen - comp.lang.asm.x86:) Actually, writing portable code is harder than it seems ... 2 - ((v & 0x00800000) >> 23); The next step is to ... to generate different functions with different parameters ... Where did Fortran go? - comp.lang.fortran... easier, there is no compile and link step, you modify ... du jour are effectively dead, while fortran seems to be ... that some Fortran 2003 has sneaked in. (PARAMETER with ... [comp.publish.cdrom] CD-Recordable FAQ, Part 1/4 - comp.publish ...Archive-name: cdrom/cd-recordable/part1 Posting-Frequency: monthly Last-modified: 2008/10/09 Version: 2.71 Send corrections and updates to And... Leap second bug? - comp.protocols.time.ntpI believe that ntpd will ignore the extras. Four, Five ... The biggest problem seems to be the computer itself ... Is this a bug or is there a config parameter which lets me ... Drawing using glDrawArrays - iDevGames... my calls to glVertexPointer, glColorPointer and glDrawArrays have incorrect parameters, the stride ... and the multiples of 8 just gets me lucky. Well your stride seems ... glDrawArrays - OOgtech.orgWe can ignore the boiler plate and start playing (or ... you indeed want to use the passed colors. - glDrawArrays ... keep this to zero to save explaining what is stride. 7/18/2012 1:03:47 PM
|