# glfwReadImage

**URL:** <https://discourse.glfw.org/t/glfwreadimage/305>\
**Category:** support\
**Created:** [August 10, 2010, 7:01am UTC](https://discourse.glfw.org/t/glfwreadimage/305 "2010-08-10T07:01:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [August 10, 2010, 7:01am UTC](https://discourse.glfw.org/t/glfwreadimage/305/1 "2010-08-10T07:01:06Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Tuesday, August 10, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/48b4f1e0/#a7e5):

Hi,

I want to manipulate the Image-Data, which I got from the glfwReadImage-  
Function. I loaded a tga-File with an alpha-channel.

Now I have two questions:

1. What means the Flag: GLFW\_ORIGIN\_UL\_BIT ?? does it work correctly?

I had created an 256x256 TGA-File with GIMP and then saved it with “Origin in  
the Upper Left”. If I read this file with glfwReadImage and then texture it on  
a quad, it is painted reverse! If I REMOVE the flag GLFW\_ORIGIN\_UL\_BIT  
from the glfwReadImage and replace it with a 0, then it appears correct! If I  
create in GIMP a TGA-File, which is NOT saveing the Origin in the upper left  
and then I use glfwReadImage with the GLFW\_ORIGIN\_UL\_BIT-Flag, it is ALSO  
painted reverse!  
Can someone explain me plz, how the usage of this flag is meant?

2. Whats the internal format of GLFWimage ?

I loaded a TGA with alphachannel and it is correct painted. The transparent is  
correct set. That means, the data in GLFWImage  
seems to be correct. But how can I manipulate the Data in the GLFWImage-  
Struct?

I have read, that in GL\_RGBA-Mode the Pixels are linear stored from the  
bottom left to the upper right? Correct?  
for example I want to draw a simple line into my loaded Image:

GLFWImage img;

//Read the Stuff ….

//Manipulate  
for(int i=0; i\< 100; i+=4)  
{  
img.date\_ = 255;  
img.date = 0;  
img.date = 0;  
img.date = 0;  
}

I thougt, I would get a horizontal red line at the bottom of my image but that  
is not the case. I can see one small line at the bottom (much to small) and  
one synchron thin line at the top of the image! Does anybody know, what I do  
wrong?  
I have checked img.Format and it is correct -\> GL\_RGBA! The image is correct  
painted, only my modification seems to be incorrect ☹

Thanx so much for help!! 🙂

Grtz Soul

\_

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [August 10, 2010, 7:04am UTC](https://discourse.glfw.org/t/glfwreadimage/305/2 "2010-08-10T07:04:15Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Tuesday, August 10, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/48b4f1e0/#da69):

//sry, this code-part is correct. Ths is the part which does not work

```
//Manipulate for(int i=0; i< 100; i+=4)
{
img.date[i] = 255; 
img.date[i+1] = 0;
img.date[i+2] = 0; 
img.date[i+3] = 0; 
}
```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [August 11, 2010, 6:22pm UTC](https://discourse.glfw.org/t/glfwreadimage/305/3 "2010-08-11T18:22:09Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Wednesday, August 11, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/48b4f1e0/#c889):

hmmm…does nobody know an answer ? ☹

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [August 11, 2010, 9:14pm UTC](https://discourse.glfw.org/t/glfwreadimage/305/4 "2010-08-11T21:14:57Z")

</div>

**[elmindreda](https://sourceforge.net/u/elmindreda/)** wrote on [Wednesday, August 11, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/48b4f1e0/#8706):

The orientation is not related to the pixel format.

You have written nothing about how you set up your quad.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex035/uploads/glfw/original/1X/b8cdefe6b61b8d5aee6c43b2c56e9cf5eabecfe4.svg) [@system](https://discourse.glfw.org/u/system)\
**Post date:** [August 12, 2010, 7:31am UTC](https://discourse.glfw.org/t/glfwreadimage/305/5 "2010-08-12T07:31:13Z")

</div>

**[soulfreezer](https://sourceforge.net/u/soulfreezer/)** wrote on [Thursday, August 12, 2010](https://sourceforge.net/p/glfw/discussion/247562/thread/48b4f1e0/#23ed):

Hi Camilla,

I have solved the Problem. The redundant apperance of the pixels is maybe a  
repeating drawing of the Texture on the Quad?  
Maybe cause of my Perspective? If I translate the quad nearer on z-axis (less  
negative value), then it looks correct. I have switched then to Ortho-Mode  
and set the viewport exactly to Screensize. Then I drawed the texture against  
the clock on the quad. The Quad has the size of 256x256 and the texture also.  
Also I activated Backface-Culling. Now it looks correct on each translate-  
combination. Strange thing………
