Followers 0

## 11 posts in this topic

Hi, i've been working on a project for a while now and have successfully loaded 32,16, and 8 bits textures into opengl without any conversion.

Now im planning to add 1 and 4 bits textures as well, but im not sure if the last one is doable.

For the 1-bit texture, im just gonna try that when i have the time, but i can't seem to find any relevant information for 4-bits textures.

Any idea?

I also dont really understand how glPixelMapfv works exactly, but i understand it can be used for color remapping or something like that.

Do i really need it for 1-bit textures?

FYI, that's how my code load textures, for now:

        int GLType = 0;
int GLFormat = 0;
int NumElements = 0;

switch(Format)
{
case scrf_32:
NumElements = 4;
GLFormat = GL_BGRA;
GLType = GL_UNSIGNED_BYTE;
break;
case scrf_16:
NumElements = 4;
GLFormat = GL_BGRA;
GLType = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case scrf_8c:
NumElements = 3;
GLFormat = GL_RGB;
GLType = GL_UNSIGNED_BYTE_2_3_3_REV;
break;
case scrf_8g:
NumElements = 1;
GLFormat = GL_LUMINANCE;
GLType = GL_UNSIGNED_BYTE;
break;
}

...

glTexImage2D(GL_TEXTURE_2D, 0, NumElements, w, h, 0, GLFormat, GLType, pTex);

Edited by Vortez
0

##### Share on other sites

You linked to a post with multiple solutions to the 1-bit issue, and didn't specify which option you're planning to use. It looks like all of the solutions work fine for 4-bit in the same way they work for 1-bit.

I'll guess you're using the example with glPixelMapfv since you're asking about glPixelMapfv. You do need glPixelMapfv because that 2 in the call is saying your color information is 1-bit wide. To do the same with 4-bit, you'd set up a color map using size 16 (2^4) instead of 2 (2^1). You'd have to use the right 16 colors in index, and probably need an index for R, G, B, and A. For example, if you have 1 bit for each component, you'd repeat 0.0, 1.0 8 times at one end {0.0, 1.0, 0.0, 1.0, 0.0, 1.0...} and 0.0 repeated 8 times, 1.0 repeated 8 times at the other end.

1

##### Share on other sites

You linked to a post with multiple solutions to the 1-bit issue, and didn't specify which option you're planning to use. It looks like all of the solutions work fine for 4-bit in the same way they work for 1-bit.

I'll guess you're using the example with glPixelMapfv since you're asking about glPixelMapfv. You do need glPixelMapfv because that 2 in the call is saying your color information is 1-bit wide. To do the same with 4-bit, you'd set up a color map using size 16 (2^4) instead of 2 (2^1). You'd have to use the right 16 colors in index, and probably need an index for R, G, B, and A. For example, if you have 1 bit for each component, you'd repeat 0.0, 1.0 8 times at one end {0.0, 1.0, 0.0, 1.0, 0.0, 1.0...} and 0.0 repeated 8 times, 1.0 repeated 8 times at the other end.

Thanks a lot, im gonna try it out when my code is ready. What i dont get is, why do you have to repeat 0.0 and 1.0 eight time exactly?

Do you really have a need for 1-bit and 4-bit textures (as well as 16-bit textures) in your game engine, or are you simply trying to be complete with your texture support? I doubt any hardware (desktop anyway) has native support for those formats. I wouldn't be surprised in the slightest if the driver converted them to a higher bit depth, in which case you aren't saving yourself anything. You are probably much better off using compressed texture formats like S3TC (and hopefully in the future ASTC) since those will give you higher quality while at the same time saving space and bandwidth.

Well, if i was writting a game, i would agree with you and use pretty much 24 or 32 bits textures only, but this code is for a remote desktop application, not a game. Since i already made the other formats (32, 16 and 8), i said what the hell, let's try those last 2. Always loved a good challenge too.

Edited by Vortez
1

##### Share on other sites

Thanks a lot, im gonna try it out when my code is ready. What i dont get is, why do you have to repeat 0.0 and 1.0 eight time exactly?

You're dealing with 16 combinations for a 4-bit value, and the pixel maps are just a look-up table. You obviously want entries for each valid look-up value in a look-up table. In R1G1B1A1 format, you'd set up the values to say 1.0 if the bit is set and 0.0 if the bit is not set. For example, the four bits 1010 (value=10) in R1G1B1A1 is R=1, G=0, B=1, A=0. So you'd want dataRed[10]=1.0, dataGreen[10]=0.0, dataBlue[10]=1.0, and dataAlpha[10]=0.0. dataRed would be {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0} since its bit is 0 for 0-7 and 1 for 8-15 (bold, underline is element 10). If the format is not R1G1B1A1, you're likely dealing with an actual look-up table in the source image and need your glPixelMapfv values to correspond to the pixel map in the image.

1

##### Share on other sites

Humm, after passing 2 days rewritting part of my code to make this work, i got the 1 bit texture working, but i can't seem to get the 4 bit work. After re-reading your post above, i think you misunderstood me. im not using R1G1B1A1 format, but rather i use 4 bits of grayscale data. I tryed loading the texture this way but it didn't work

	case scrf_32:
NumElements = 4;
GLFormat = GL_BGRA;
GLType   = GL_UNSIGNED_BYTE;
break;
case scrf_16:
NumElements = 4;
GLFormat = GL_BGRA;
GLType   = GL_UNSIGNED_SHORT_1_5_5_5_REV;
break;
case scrf_8c:
NumElements = 3;
GLFormat = GL_RGB;
GLType   = GL_UNSIGNED_BYTE_2_3_3_REV;
break;
case scrf_8g:
NumElements = 1;
GLFormat = GL_LUMINANCE;
GLType   = GL_UNSIGNED_BYTE;
break;
case scrf_4:   // this dont work
NumElements = 1;
GLFormat = GL_LUMINANCE4;
GLType   = GL_UNSIGNED_BYTE;
break;
case scrf_1:   //  <--- this work
float index[] = {0.0, 1.0};

glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, index);

NumElements = 1;
GLFormat = GL_COLOR_INDEX;
GLType   = GL_BITMAP;
break;
}

...

glTexImage2D(GL_TEXTURE_2D, 0, NumElements, w, h, 0, GLFormat, GLType, pTex);


Any idea?

1

##### Share on other sites

I just tryed with this code instead and it also failed

	case scrf_4:
{
float index[16] = {0.0f, (1.0f/15.0f), (2.0f/15.0f), (3.0f/15.0f), (4.0f/15.0f), (5.0f/15.0f), (6.0f/15.0f), (7.0f/15.0f), (8.0f/15.0f), (9.0f/15.0f), (10.0f/15.0f), (11.0f/15.0f), (12.0f/15.0f), (13.0f/15.0f), (14.0f/15.0f), 1.0f};

glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 16, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 16, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 16, index);
glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 16, index);
}

NumElements = 1;
GLFormat = GL_COLOR_INDEX;
GLType   = GL_BITMAP; // Also tryed GL_LUMINANCE4 and GL_LUMINANCE, without luck...
break;


Edited by Vortez
1

##### Share on other sites

I got some result using

		NumElements = GL_LUMINANCE4;
GLFormat = GL_LUMINANCE;
GLType   = GL_UNSIGNED_BYTE;



but it's all blurry. At least i see something. Gonna make some test app to clear this up.

1

##### Share on other sites

To rule out a bunch of unrelated possible issues, can you ensure mipmapping is completely disabled and use GL_NEAREST instead of GL_LINEAR if you're not already doing so?

You might also try loading the data into 32-bit RGBA to help debugging. So you'd load 4-bit greyscale -> 32-bit RGBA. Then you'd at least know if the reading is the part messing up.

If you can easily make a test app demonstrating the problem, that would help a lot. I don't actually mess with 4-bit textures, and you're getting far enough along that nothing's just jumping out at me any more. So, congratulations for the progress you've made so far.

On a semi-unrelated note, your variable "NumElements" constantly throws me off. You seem to be using it as internalFormat, and I'm constantly ignoring it since I don't really care how many elements you have.

0

##### Share on other sites

To rule out a bunch of unrelated possible issues, can you ensure mipmapping is completely disabled and use GL_NEAREST instead of GL_LINEAR if you're not already doing so?

Yea, turn out i was using GL_LINEAR instead of GL_NEAREST, i have no idea why... but that's not the problem with the image. I did a simple test program, and it turn out it use the whole byte instead of half of it, hence the weird picture. I know the image is ok since im taking it with another test program and draw it using gdi, and it's ok.

On a semi-unrelated note, your variable "NumElements" constantly throws me off. You seem to be using it as internalFormat, and I'm constantly ignoring it since I don't really care how many elements you have.

Yea i noticed that too! i really need to change that variable name .

I also made a thread here so i dont need to repeat what i just wrote.

Hope someone will find a solution... otherwise, i give up lol, and that dosen't happen often.

I beleive glPixelMapfv is the way to go, but i can't figure out how to use it with 4 bits

EDIT: i guess i could try to make a more portable test project tomorow that don't use my library, im too tired to make it tonigh that's for sure.

Edited by Vortez
1

##### Share on other sites

If you do try the pixel map approach again, one thing you'll definitely want to do is set alpha to 1 for all 16 values instead of x/15. You're basically creating intensity instead of luminance by setting alpha to x/15.

0

##### Share on other sites

Well thanx, but i decided to do a 4 to 8 bits conversion since it appear that's the only solution. Since im doing the conversion on the recv side of the network im still saving bandwith, and the conversion don't seem to affect performance in a noticable way. Thanx a lot for your help anyway. It's all working now .

EDIT: Yep, it's faster using the 4bpp than 8bpp mode, even with the conversion.

Edited by Vortez
1

## Create an account

Register a new account

Followers 0

• ### Similar Content

• So it's been a while since I took a break from my whole creating a planet in DX11. Last time around I got stuck on fixing a nice LOD.
A week back or so I got help to find this:
https://github.com/sp4cerat/Planet-LOD
In general this is what I'm trying to recreate in DX11, he that made that planet LOD uses OpenGL but that is a minor issue and something I can solve. But I have a question regarding the code
He gets the position using this row
vec4d pos = b.var.vec4d["position"]; Which is then used further down when he sends the variable "center" into the drawing function:
if (pos.len() < 1) pos.norm(); world::draw(vec3d(pos.x, pos.y, pos.z));
Inside the draw function this happens:
draw_recursive(p3[0], p3[1], p3[2], center); Basically the 3 vertices of the triangle and the center of details that he sent as a parameter earlier: vec3d(pos.x, pos.y, pos.z)
Now onto my real question, he does vec3d edge_center[3] = { (p1 + p2) / 2, (p2 + p3) / 2, (p3 + p1) / 2 }; to get the edge center of each edge, nothing weird there.
But this is used later on with:
vec3d d = center + edge_center[i]; edge_test[i] = d.len() > ratio_size; edge_test is then used to evaluate if there should be a triangle drawn or if it should be split up into 3 new triangles instead. Why is it working for him? shouldn't it be like center - edge_center or something like that? Why adding them togheter? I asume here that the center is the center of details for the LOD. the position of the camera if stood on the ground of the planet and not up int he air like it is now.

Full code can be seen here:
https://github.com/sp4cerat/Planet-LOD/blob/master/src.simple/Main.cpp
If anyone would like to take a look and try to help me understand this code I would love this person. I'm running out of ideas on how to solve this in my own head, most likely twisted it one time to many up in my head
Toastmastern

• I googled around but are unable to find source code or details of implementation.
What keywords should I search for this topic?
Things I would like to know:
A. How to ensure that partially covered pixels are rasterized?
Apparently by expanding each triangle by 1 pixel or so, rasterization problem is almost solved.
But it will result in an unindexable triangle list without tons of overlaps. Will it incur a large performance penalty?
How to ensure proper synchronizations in GLSL?
GLSL seems to only allow int32 atomics on image.
C. Is there some simple ways to estimate coverage on-the-fly?
In case I am to draw 2D shapes onto an exisitng target:
1. A multi-pass whatever-buffer seems overkill.
2. Multisampling could cost a lot memory though all I need is better coverage.
Besides, I have to blit twice, if draw target is not multisampled.

• By mapra99
Hello

I am working on a recent project and I have been learning how to code in C# using OpenGL libraries for some graphics. I have achieved some quite interesting things using TAO Framework writing in Console Applications, creating a GLUT Window. But my problem now is that I need to incorporate the Graphics in a Windows Form so I can relate the objects that I render with some .NET Controls.

To deal with this problem, I have seen in some forums that it's better to use OpenTK instead of TAO Framework, so I can use the glControl that OpenTK libraries offer. However, I haven't found complete articles, tutorials or source codes that help using the glControl or that may insert me into de OpenTK functions. Would somebody please share in this forum some links or files where I can find good documentation about this topic? Or may I use another library different of OpenTK?

Thanks!

• Hello, I have been working on SH Irradiance map rendering, and I have been using a GLSL pixel shader to render SH irradiance to 2D irradiance maps for my static objects. I already have it working with 9 3D textures so far for the first 9 SH functions.
In my GLSL shader, I have to send in 9 SH Coefficient 3D Texures that use RGBA8 as a pixel format. RGB being used for the coefficients for red, green, and blue, and the A for checking if the voxel is in use (for the 3D texture solidification shader to prevent bleeding).
My problem is, I want to knock this number of textures down to something like 4 or 5. Getting even lower would be a godsend. This is because I eventually plan on adding more SH Coefficient 3D Textures for other parts of the game map (such as inside rooms, as opposed to the outside), to circumvent irradiance probe bleeding between rooms separated by walls. I don't want to reach the 32 texture limit too soon. Also, I figure that it would be a LOT faster.
Is there a way I could, say, store 2 sets of SH Coefficients for 2 SH functions inside a texture with RGBA16 pixels? If so, how would I extract them from inside GLSL? Let me know if you have any suggestions ^^.
• By KarimIO
EDIT: I thought this was restricted to Attribute-Created GL contexts, but it isn't, so I rewrote the post.
Hey guys, whenever I call SwapBuffers(hDC), I get a crash, and I get a "Too many posts were made to a semaphore." from Windows as I call SwapBuffers. What could be the cause of this?
Update: No crash occurs if I don't draw, just clear and swap.
static PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // 24Bit Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; if (!(hDC = GetDC(windowHandle))) return false; unsigned int PixelFormat; if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return false; if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return false; hRC = wglCreateContext(hDC); if (!hRC) { std::cout << "wglCreateContext Failed!\n"; return false; } if (wglMakeCurrent(hDC, hRC) == NULL) { std::cout << "Make Context Current Second Failed!\n"; return false; } ... // OGL Buffer Initialization glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); glBindVertexArray(vao); glUseProgram(myprogram); glDrawElements(GL_TRIANGLES, indexCount, GL_UNSIGNED_SHORT, (void *)indexStart); SwapBuffers(GetDC(window_handle));

• 14
• 12
• 22
• 11
• 28