I'm writing my 3D engine, without OpenGL or DirectX. Every 3D calculations are my own code. When a whole frame is calculated (a 2D color array), I have to draw it to a window, and to do this I use GLUT and OpenGL. But, I don't use OpenGL's 3D features.
So I have a 2D color array (actually a 1D unsigned char array, which is used as a 2D array), and I have to draw it with OpenGL/GLUT, in an efficient way.
There are two important things:
- performance (FPS value)
- easy to resize, auto-scale the window's content
I wrote 3 possible solutions:
- 2 for loop, every pixel is a GL_QUADS with a color. Very slow, but working good, and window resize is also working good.
- glDrawPixels, not the most efficient, but I'm satisfied with the FPS-value. Unfortunately, when I resize the window, the content don't scale automatically. I tried to write my own resize callback function, but it never worked. Green is not missing, it's OK.
- The best solution is probably to make a texture from that unsigned char array, and draw only one GL_QUADS. Very fast, and window resize working good, the content scaling automatically. But, and this is my question, green color component is missing, I don't know why.
Some hours ago, I used float array, 3 components, and 0...1 values. Green was missing, so I decided to use unsigned char array, because it's smaller. Now, I use 4 components, but the 4th is always unused. Values are 0...255. Green is still missing. My texturing code:
GLuint TexID;
glGenTextures(1, &TexID);
glPixelStorei(GL_UNPACK_ALIGNMENT, TexID); // I tried PACK/UNPACK and ALIGNMENT/ROW_LENGTH, green is still missing
glTexImage2D(GL_TEXTURE_2D, 0, RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, a->output);
glTexParametri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParametri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParametri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParametri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBindTexture(GL_TEXTURE_2D, TexID);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
// glTexCoord2f ... glVertex2f ... four times
glEnd();
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &TexID);
If I use glDrawPixels, it is working good, R, G and B components are on the window. But when I use the code above with glTexImage2D, green component is missing. I tried a lots of things, but nothing solved this green-issue.
I draw coloured cubes with my 3D engine, and which contains green component (for example orange, white or green), it has a different color, without the green component. Orange is red-like, green is black, etc. 3D objects which doesn't contain green component, are good, for example red cubes are red, blue cubes are blue.
I think, glTexImage2D's parameters are wrong, and I have to change them.
glDrawPixels()? - Anton SavinglColor3f(1,1,1)before yourglBegin()help? - genpfault