Menu

Use DirectOpenGL command

Help
M.a.
2020-07-01
2020-07-08
  • M.a.

    M.a. - 2020-07-01

    Hi,
    How can I use opengl commands by GLDirectOpenGL correctly?
    I know I must use OnRender event but my commands not work completely,
    for example for display a triangle with three colors at the vertices I use this code :

    procedure TForm1.GLDirectOpenGL1Render(Sender: TObject;
      var rci: TGLRenderContextInfo);
    begin
      glBegin(GL_TRIANGLES);
        glColor3f(1, 0, 0);
        glVertex3f( 0.0, 1.0, 0.0);
        glColor3f(0, 1, 0);
        glVertex3f(-1.0,-1.0, 0.0);
        glColor3f(0, 0, 1);
        glVertex3f( 1.0,-1.0, 0.0);
      glEnd;
    end;
    

    But I have a triangle with one color (Green).
    Where is my mistake?

     

    Last edit: M.a. 2020-07-01
  • Jerson Seling

    Jerson Seling - 2020-07-08

    Try this:

    procedure TForm1.GLDirectOpenGL1Render(Sender: TObject;
      var rci: TGLRenderContextInfo);
    begin
      //rci.GLStates.Disable(stCullFace);
      rci.GLStates.Enable(stColorMaterial); //add use GLState
      rci.GLStates.Disable(stLighting);
      glBegin(GL_TRIANGLES);
        // glNormal3f(0,0,-1);
        glColor3f(1, 0, 0);     glVertex3f(0, 1, 0);
        glColor3f(0, 1, 0);     glVertex3f(-1, -1, 0);
        glColor3f(0, 0, 1);     glVertex3f(1, -1, 0);
      glEnd;
    end;
    

    GLGraph .pas TGLHeightField.BuildList may help you with this.

    Your triangle is green probably because you have another object in scene that is green and its state configuration is passing to the DirectOpenGL render. You need to configure this state before draw something.

     

    Last edit: Jerson Seling 2020-07-08

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.