PDA

View Full Version : window content disapperas after moving



thonel
05-07-2009, 03:21 AM
hi there
im completely new to opengl and i have no clue at all xD
im trying to get it to work on ubuntu linux with c# and tao.

finally it works but when i move the window around or cover it with another window the drawings disappear.

i read that this can be solved via the reshape function callback but it seems not to do anything.

i guess its just a minor flaw of mine but as i have no experience i cant find it.

this is my complete code:


using System;
using System.Collections.Generic;
using Tao.FreeGlut;
using Tao.OpenGl;

namespace FreeGlutExample
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// initialise glut library
Glut.glutInit();

// initialise the window settings
Glut.glutInitDisplayMode(Glut.GLUT_RGB | Glut.GLUT_SINGLE);
Glut.glutInitWindowSize(400, 400);
Glut.glutInitWindowPosition(400, 200);
Glut.glutCreateWindow("GdgDV Uebung 2");

Glu.gluOrtho2D(0,400,400,0); /* how object is mapped to window */

// do our own initialisation
Init();

// set the callback functions
Glut.glutDisplayFunc(new Glut.DisplayCallback(Display));
Glut.glutReshapeFunc(new Glut.ReshapeCallback(Reshape));


// enter the main loop. Glut will be here permanently from now on
// until we quit the program
Glut.glutMainLoop();
}


/// <summary>
/// initialises the openGL settings
/// </summary>
private static void Init()
{
Gl.glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
}

/// <summary>
/// called when the window changes size
/// </summary>
/// <param name="w">new width of the window</param>
/// <param name="h">ne height of the window</param>
private static void Reshape(int w, int h)
{
if (h == 0) h = 1;
Glut.glutPostRedisplay();
}

/// <summary>
/// the display callback function
/// </summary>
private static void Display()
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

// 2 kreis in orange
Gl.glColor3f(1, 0.5f, 0);
circle(200, 200, 200, 360, 0);

// 1 fünfeck in gelb
Gl.glColor3f(1, 1, 0);
circle(200, 200, 200, 5, -1f);

// 3 kreis in blau
Gl.glColor3f(0, 1, 1);
circle(200, 200, 162, 360, 0);

// 4 fünfeck in gelb
Gl.glColor3f(1, 1, 0);
circle(200, 200, 162, 5, -1f);

}


public static void circle(float center_x, float center_y, float radius, float steps, float rotation) {
double PI2 = Math.PI*2;
float x = 0.0f;
float y = 0.0f;

Gl.glBegin(Gl.GL_POLYGON);
for( double theta = rotation; theta < PI2; theta += PI2 / steps ) {
x = (float) (center_x + ( Math.Cos( theta ) * radius));
y = (float) (center_y + ( Math.Sin( theta ) * radius));
Gl.glVertex2f(x, y);
}
Gl.glEnd();
}
}
}


it would be great if you could help a lost beginner ;)

thanks in advance

Nighthawk
05-07-2009, 06:32 AM
Redrawing the window all the time could help:



void myIdleFunction()
{
glutPostRedisplay();
}

glutIdleFunc(myIdleFunction);

dletozeun
05-07-2009, 09:30 AM
In addition move this to the reshape function:

Glu.gluOrtho2D(0,w,h,0);

and call also glViewport to set the new viewport size.

thonel
05-11-2009, 12:59 AM
Redrawing the window all the time could help:



void myIdleFunction()
{
glutPostRedisplay();
}

glutIdleFunc(myIdleFunction);


thanks a lot. this and activating double buffering works just fine.




In addition move this to the reshape function:

Glu.gluOrtho2D(0,w,h,0);

and call also glViewport to set the new viewport size.

maybe im doing it wrong but this causes an empty window..

dletozeun
05-11-2009, 05:40 AM
You do it wrong, your Reshape function is pretty useless in the above code and do not fulfill his role in case of window resizing.

Look for glut example code with Google, you will find many valid glut base sample codes.