Forum > OpenGL

32bit (transparent) color in OpenGL control component?

<< < (2/2)

Peiman:
Sorry,
I think my problem with OpenGL is more than I have imagined. Now neither the 4f nor 3f colors won't work! Ironically the only thing I need now is simple transparent surfaces! I think it is easier to design a new engine rather use opengl for this.

Even with the provided example of opengl component (with 3f colors). it mess up the depth and colors of the cube.

--- Code: ---
  glClearColor(1.0, 1.0, 1.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0, double(width) / height, 0.1, 100.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  glTranslatef(0.0, 0.0,-6.0);
  glRotatef(cube_rotationz, cube_rotationx, cube_rotationy,1);
  glBegin(GL_QUADS);
          glColor3f(0.0,1.0,0.0);                              // Set The Color To Green
          glVertex3f( 1.0, 1.0,-1.0);                  // Top Right Of The Quad (Top)
          glVertex3f(-1.0, 1.0,-1.0);                  // Top Left Of The Quad (Top)
          glVertex3f(-1.0, 1.0, 1.0);                  // Bottom Left Of The Quad (Top)
          glVertex3f( 1.0, 1.0, 1.0);                  // Bottom Right Of The Quad (Top)
  glEnd();
  glBegin(GL_QUADS);
          glColor3f(1.0,1.0,0.0);                              // Set The Color To Orange
          glVertex3f( 1.0,-1.0, 1.0);                  // Top Right Of The Quad (Bottom)
          glVertex3f(-1.0,-1.0, 1.0);                  // Top Left Of The Quad (Bottom)
          glVertex3f(-1.0,-1.0,-1.0);                  // Bottom Left Of The Quad (Bottom)
          glVertex3f( 1.0,-1.0,-1.0);                  // Bottom Right Of The Quad (Bottom)
  glEnd();
  glBegin(GL_QUADS);
          glColor3f(1.0,0.0,0.0);                              // Set The Color To Red
          glVertex3f( 1.0, 1.0, 1.0);                  // Top Right Of The Quad (Front)
          glVertex3f(-1.0, 1.0, 1.0);                  // Top Left Of The Quad (Front)
          glVertex3f(-1.0,-1.0, 1.0);                  // Bottom Left Of The Quad (Front)
          glVertex3f( 1.0,-1.0, 1.0);                  // Bottom Right Of The Quad (Front)
  glEnd();
  glBegin(GL_QUADS);
          glColor3f(1.0,1.0,0.0);                              // Set The Color To Yellow
          glVertex3f( 1.0,-1.0,-1.0);                  // Bottom Left Of The Quad (Back)
          glVertex3f(-1.0,-1.0,-1.0);                  // Bottom Right Of The Quad (Back)
          glVertex3f(-1.0, 1.0,-1.0);                  // Top Right Of The Quad (Back)
          glVertex3f( 1.0, 1.0,-1.0);                  // Top Left Of The Quad (Back)
  glEnd();
  glBegin(GL_QUADS);
          glColor3f(0.0,0.0,1.0);                              // Set The Color To Blue
          glVertex3f(-1.0, 1.0, 1.0);                  // Top Right Of The Quad (Left)
          glVertex3f(-1.0, 1.0,-1.0);                  // Top Left Of The Quad (Left)
          glVertex3f(-1.0,-1.0,-1.0);                  // Bottom Left Of The Quad (Left)
          glVertex3f(-1.0,-1.0, 1.0);                  // Bottom Right Of The Quad (Left)
  glEnd();
  glBegin(GL_QUADS);
          glColor3f(1.0,0.0,1.0);                              // Set The Color To Violet
          glVertex3f( 1.0, 1.0,-1.0);                  // Top Right Of The Quad (Right)
          glVertex3f( 1.0, 1.0, 1.0);                  // Top Left Of The Quad (Right)
          glVertex3f( 1.0,-1.0, 1.0);                  // Bottom Left Of The Quad (Right)
          glVertex3f( 1.0,-1.0,-1.0);                  // Bottom Right Of The Quad (Right)
  glEnd();

  Speed := double(OpenGLControl1.FrameDiffTimeInMSecs)/10;

  cube_rotationx += 1.2 * Speed;
  cube_rotationy += 1 * Speed;
  cube_rotationz += 1 * Speed;

  OpenGLControl1.SwapBuffers;

end;

--- End code ---

 

User137:
These should only be called once when the program starts:

--- Quote ---  glClearColor(1.0, 1.0, 1.0, 1.0);
  ..
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(45.0, double(width) / height, 0.1, 100.0);
  glMatrixMode(GL_MODELVIEW)
--- End quote ---

You didn't post the actual transparency code... The actual rendering there looks just fine, if with glColor3f(0.0,1.0,0.0); you assume to fully use green color and rely on texture alpha-channel.

Also what kind of texture are you loading and how? Simplest format i imagine is with PNG that supports alpha. But when it comes to displaying anything transparently, if you use for example glColor4f(1,1,1,0.5), you could even load a JPEG with simple RGB and show it half transparent. Is it texture alpha-channel you are after or both...?

Peiman:
I don't want to use any texture image. As I've mentioned, I only need COLOR, like the simple solidbrush type in GDI+. That's why I think OpenGL is not the best choice for me. (specially as I don't also need a high speed in rendering).

I think the problem is that I have misunderstood opengl. I supposed it also sorts depths by its own. While its official website has stated I have to do this prior using color4f (without textures). (Does GLScene does it automatically?). So I started to write/find sorting algorithms.

User137:
OpenGL doesn't automatically sort polygons, and if it did, it could be extremely memory consuming and slow. Also the way color and depthbuffer works, everything is always plot on top. So you can't for example draw a wall behind a glass window, but you have to draw the wall first.

glColor4f works equally well with "solidbrush" you mean, which is simply a untextured polygon.

Also, your faces were supposed to be colored like this:


--- Code: ---  glBegin(GL_QUADS);
          glColor4f(0.0,1.0,0.0, 0.5);                // Set The Color To half transparent Green
          glVertex3f( 1.0, 1.0,-1.0);                  // Top Right Of The Quad (Top)
          glVertex3f(-1.0, 1.0,-1.0);                  // Top Left Of The Quad (Top)
          glVertex3f(-1.0, 1.0, 1.0);                  // Bottom Left Of The Quad (Top)
          glVertex3f( 1.0, 1.0, 1.0);                  // Bottom Right Of The Quad (Top)
  glEnd();
--- End code ---


--- Quote ---I think it is easier to design a new engine rather use opengl for this.
--- End quote ---
OpenGL is a graphics API like windows SDK is. Every hardware accelerated graphics engine uses either OpenGL or DirectX (or both). Doing it non-accelerated with just CPU will be a huge drop in performance.

Navigation

[0] Message Index

[*] Previous page

Go to full version