Wierd Image shown

Hi,

I am trying to show the usual basic triangle to test my OpenGl set up, but I see this happy looking image.

To obtaine this I did the following :

In the init function called once

        Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        Gl.glMatrixMode(Gl.GL_PROJECTION);
        Gl.glLoadIdentity();
        Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 

In the drawing function called each X per second.

        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
        Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
        Gl.glBegin(Gl.GL_TRIANGLES);
        Gl.glColor3f(1.0f, 1.0f, 1.0f);
        Gl.glVertex3d(0.5, 1.0,0.0);
        Gl.glVertex3d(0.0, 0.0, 0.0);
        Gl.glVertex3d(1.0, 0.0, 0.0);
        Gl.glEnd();

Do you guys have any pointer or idea what I might be doing wrong ? (The swapBuffer method is called after).

I am using Tao framework for C# and it worked yesterday. It also did the same bug when I was doing openGL with C++.

Don’t draw anything first to make sure that you at least get a black background if you don’t it could be something else as I don’t really see anything wrong with that render code and I don’t think it would cause something like that to happen. Have you set up the context correctly? Are you swapping the buffers? those are just thing that come to mind.

You have a good point. The image is indeed not black even if I don’t draw anything.If I just do the

OpenGLWindow.InitializeContexts();

The image is wierd. However, if I put my code in the form’s loading event.

   /// <summary>
    /// This initialize openGL and the manager when the Form load
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void Form1_Load(object sender, EventArgs e)
    {

       Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);

    }

The OpenGl is black.

If I put this code in the LoadForm event the openGL seems to Draw what I’m asking for.

        Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        Gl.glMatrixMode(Gl.GL_PROJECTION);
        Gl.glLoadIdentity();
        Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
        Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
        Gl.glBegin(Gl.GL_TRIANGLES);
        Gl.glColor3f(1.0f, 1.0f, 1.0f);
        Gl.glVertex3d(0.5, 1.0, 0.0);
        Gl.glVertex3d(0.0, 0.0, 0.0);
        Gl.glVertex3d(1.0, 0.0, 0.0);
        Gl.glEnd();

But if I put this code

        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
       //Gl.glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
       Gl.glBegin(Gl.GL_TRIANGLES);
       Gl.glColor3f(1.0f, 1.0f, 1.0f);
       Gl.glVertex3f(1.0f, 0.0f, 0.0f);
       Gl.glColor3f(0.0f, 1.0f, 0.0f);
       Gl.glVertex3f(5.0f, 0.0f, -4.0f);
       Gl.glColor3f(0.0f, 0.0f, 1.0f);
       Gl.glVertex3f(0.0f, 0.0f, 6.0f);
       Gl.glEnd();

it shows this :

Another strange thing is that if I put the window in minimize and take it back I have this. Even if I use the good or bad code. It seems like something is redrawing on some old random buffer.

This seems like a buffer problem. I’m using double buffer in the Pixel format, well tao’s framework is using it.

If you guys have any pointer or idea shoot some !

You need to draw your stuff when the context is created and active.

So…
-first case) Only ContextInit and no glClear
You are not cleaning the framebuffer and nobody else will to the dirty work for you.
-second case) glClear in the form loading
You are lucky that you have the active context here and everything work fine.
-third case) draw code in the form loading
same as above
-fourth case) drawing without setup the projection matrix and random vertex position
All the vertexes have the same Y, what do you expect to see?
-fifth case) restore from minimization
When you restore the windows from minimization you have to redraw the scene again. I don’t think that your application load the form every time you restore the windows. :stuck_out_tongue:

Your application don’t have a render cycle? Your drawing code should go there.