"yj1214" :
1. Why can't I just always use glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if
it works every time?
Could you give me an example where I have to use GL_UNPACK_ALIGNMENT other than 1?
2. Why does OpenGL require alignment?
can't it just read memory one by one?
"yj1214" :Could you give us examples of what doesn't work in your code ?
1. Why can't I just always use glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if
it works every time?
Could you give me an example where I have to use GL_UNPACK_ALIGNMENT other than 1?
2. Why does OpenGL require alignment?Because it's faster.
can't it just read memory one by one?It would be slower.
Well, here you go.What values did you try to make glPixelStore fail ?
( ... )
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
If I change both ALIGNMENT to other than 1
they both won't work.What exactly didn't work :
- Did glPixelStore return an error code ?
If yes, what was the error code value ?
- Or was the result of unpacking different from what you expected ?
Jean-Christophe wrote:if
"yj1214" :
1. Why can't I just always use glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
otherit works every time?
Could you give me an example where I have to use GL_UNPACK_ALIGNMENT
than 1?Could you give us examples of what doesn't work in your code ?
2. Why does OpenGL require alignment?Because it's faster.
can't it just read memory one by one?It would be slower.
Well, here you go.
**********************************************************
GLubyte text[3] = {
0xff, 0x30, 0xff
};
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); **********************************************************
This works fine.
**********************************************************
GLubyte something[15] = {
0xc0, 0xc0, 0xc0, 0xc0, 0xc0,
0xff, 0xff, 0xc0, 0xc0, 0xc0,
0xff, 0xff, 0xff, 0xff, 0xff
};
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); *********************************************************
This also works fine.
If I change both ALIGNMENT to other than 1, they both won't work. Couldexplain the point of using GL_UNPACK_ALIGNMENT other than 1? thanks.
--
This post on narkive:
http://narkive.com/GRey4bF6.3
Well, here you go.
( ... )
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
If I change both ALIGNMENT to other than 1
they both won't work.
Or am I incorrect? Each row is 12 bytes long and it is
divisible by 4, so shouldn't the alignment 4?
I have my last question,
If I have an array like this,
int x[7] = {1, 2, 3, 4, 5, 6, 7);
and the width of my pixel row is 3,
glBitmap(3, etc...);
then my alignment would be,shouldn't the alignment 4?
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
Or am I incorrect? Each row is 12 bytes long and it is divisible by 4, so
Thanks for the help, Jean-Christophe and R. wieser.
--
This post on narkive:
http://narkive.com/GRey4bF6.7
"yj1214" :
It just renders weird looking characters whenever
I use GL_UNPACK_ALIGNMENT other than 1.
I just don't really get the point of using
2, 4 and 8 since 1 will always work.
So I want an example of using 2, 4 and 8 alignment.
The alignment has got nothing to do with the number of elements/bytes in a row, but everything with the size of a single element.
Now i'm little confused...[snip]
According to these posts,
I think this illustrates your explanation of how alignment works,[Snip]
Am I not correct? i'm really confused about how alignment works...
R.Wieser wrote:a
The alignment has got nothing to do with the number of elements/bytes in
row, but everything with the size of a single element.
Now i'm little confused...
According to these posts,
StackOverflow:
OpenGL and JOGL:
http://www.felixgers.de/teaching/jogl/imageStorageMode.html
OpenGL official website:
It says alignment works with row, not with elements...
From OpenGL post,
Suppose that you have texture data with GL_RGB format (3 bytes percomponent) and a width of 123, with no padding between rows (i.e. the first byte of the first pixel of one row immediately follows the last byte of the last pixel of the previous row). The stride between rows will be 3*123 = 369 bytes. Note that 369 is not a multiple of 2 or 4.
If GL_UNPACK_ALIGNMENT is 4, and you try to upload the texture data withglTexImage2D(), the implementation will round the length of each row up to
It says alignment will round up each row's length(byte) depends onGL_UNPACK_ALIGNMENT number. It didn't say it will round up each element's length...
I think this illustrates your explanation of how alignment works,
Let's say each pixel has value of RGB. So each pixel has 3 bytes.
GL_UNPACK_ALIGNMENT, 4;
<address- 1><address- 2><address- 3><address-4><address- 5><address-
<address- 7><address- 8>
This illustrates explanation of alignment from different posts.
GL_UNPACK_ALIGNMENT, 4;
<address- 1><address- 2><address- 3><address-4><address- 5><address-
<address- 7><address- 8>
Am I not correct? i'm really confused about how alignment works...
Again thanks for the help!
--
This post on narkive:
http://narkive.com/GRey4bF6.10
On Thu, 03 Sep 2015 08:03:40 +0000, yj1214 wrote:...
1. Why can't I just always use glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if
it works every time?
Could you give me an example where I have to use GL_UNPACK_ALIGNMENT other than 1?You have to use it if you have padding bytes between rows. Otherwise
OpenGL will try to read the padding bytes as the start of the following
row.
2. Why does OpenGL require alignment? can't it just read memory one byIt can. That's what setting GL_UNPACK_ALIGNMENT to 1 does. But if that couldn't be changed, the application would be forced to pack rows
one?
(without padding, even when that results in mis-aligned rows (which has a negative impact upon performance).
You have to use it if you have padding bytes between rows. Otherwise
OpenGL will try to read the padding bytes as the start of the following
row.
1. Why can't I just always use glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if
it works every time?
Could you give me an example where I have to use GL_UNPACK_ALIGNMENT other than 1?
2. Why does OpenGL require alignment? can't it just read memory one by
one?
I thought alignment works with every single pixels, not every rows.
But if alignment works with every rows. not every pixels like my example above, how does alignment done with every rows?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 461 |
Nodes: | 16 (2 / 14) |
Uptime: | 40:49:17 |
Calls: | 9,363 |
Calls today: | 8 |
Files: | 13,545 |
Messages: | 6,085,501 |
Posted today: | 3 |