PDA

View Full Version : disappearing window



hcrogma
07-29-2003, 09:34 AM
AS soon as I run the program my window come and disappear right away. here is the code.
#include <glu.h>
#include <stdlib.h>
#include "glut.h"


GLfloat ctlpts[4][4][3];
GLUnurbsObj *theNurb;

void display(void) { GLfloat knots[8] = {0.0,0.0,0.0,0.0,1.0,1.0,1.0,1.0};
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glRotatef(330.0,1.,0.,0.);
glScalef(0.5,0.5,0.5);
gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,8,knots,8,knots,4*3,3,&ctlpts[0][0][0],4,4,GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);
glPopMatrix();
glFlush();
}

void init_surface(void) {
int u,v;
for( u = 0 ; u < 4 ; u++ ) {
for( v = 0 ; v < 4 ; v++ ) {
ctlpts[u][v][0] = 2.*(u-1.5);
ctlpts[u][v][1] = 2.*(v-1.5);
if ((u==1 &#0124; &#0124; u==2)&&(v==1 &#0124; &#0124; v==2))
ctlpts[u][v][2] = 3.0;
else
ctlpts[u][v][2] = -3.0; } }
}

void myinit(void) {
GLfloat dif[] = {0.7,0.7,0.7,1.0};
GLfloat spe[] = {1.0,1.0,1.0,1.0};
GLfloat shininess[] = {100.0};
glClearColor(0.0,0.0,0.0,1.0);
glMaterialfv(GL_FRONT,GL_DIFFUSE,dif);
glMaterialfv(GL_FRONT,GL_SPECULAR, spe);
glMaterialfv(GL_FRONT,GL_SHININESS,shininess);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
init_surface();
theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb,GLU_SAMPLING_TOLERANCE,25 .0);
gluNurbsProperty(theNurb,GLU_DISPLAY_MODE,GLU_FILL );
}

void myReshape(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(float)w/(float)h,3.0,8.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
}

int main(int argc,char** argv) {
glutInit(&argc, argv);

glutCreateWindow("molehill");
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
myinit();
glutInitWindowPosition(0,0);



glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glutMainLoop();

}
Thank you

c0d3Junk3Y
07-30-2003, 05:21 AM
Code snippet from http://nehe.gamedev.net

Give this a shot :

if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if (active) // Program Active?
{
if (keys[VK_ESCAPE]) // Was ESC Pressed?
{
done=TRUE; // ESC Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
DrawGLScene(); // Draw The Scene
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
}
}


if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's OpenGL Framework",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}