🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Please help

Started by
0 comments, last by todi1856 17 years, 9 months ago
I have done a simple chess board,my problem waa when i debug,it displayed on window,but when i maximun the windows the square all gone leaving the red color background only. #include<windows.h> #include<gl/gl.h> #include<gl/glu.h> #include<gl/glut.h> #include<math.h> //called to draw a scene void DisplayScene(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBegin(GL_QUADS); glColor3f(0.0f,0.0f,1.0f); // Draw A Quad glVertex3f(-80.0f, 80.0f, 0.0f); // Top Left glVertex3f( 80.0f, 80.0f, 0.0f); // Top Right glVertex3f( 80.0f,-80.0f, 0.0f); // Bottom Right glVertex3f(-80.0f,-80.0f, 0.0f); // Bottom Left static GLfloat xF=-60.0; static GLfloat yS=-40.0; static GLfloat xF1=-40.0; static GLfloat yS1=-60.0; static GLfloat a=80.0f; static GLfloat b=80.0f; static GLfloat c=60.0f; static GLfloat d=60.0f; static GLfloat xFF=-80.0; static GLfloat ySS=-60.0; static GLfloat xF2=-60.0; static GLfloat yS2=-80.0; static GLfloat a1=60.0f; static GLfloat b1=60.0f; static GLfloat c1=40.0f; static GLfloat d1=40.0f; for(int i=0;i<8;i++) { if(i%2==0) { for(int j=0;j<4;j++) { glColor3f(1.0f,1.0f,0.0f); glVertex3f(xF, a, 0.0f); glVertex3f(yS, b, 0.0f); glVertex3f(xF1,c, 0.0f); glVertex3f(yS1,d, 0.0f); xF+=40.0f; yS+=40.0f; xF1+=40.0f; yS1+=40.0f; } xF=-60.0f; yS=-40.0f; xF1=-40.0f; yS1=-60.0f; a-=40.0f; b-=40.0f; c-=40.0f; d-=40.0f; } else { for(int j=0;j<4;j++) { glColor3f(1.0f,1.0f,0.0f); glVertex3f(xFF, a1, 0.0f); glVertex3f(ySS, b1, 0.0f); glVertex3f(xF2,c1, 0.0f); glVertex3f(yS2,d1, 0.0f); xFF+=40.0f; ySS+=40.0f; xF2+=40.0f; yS2+=40.0f; } xFF=-80.0f; ySS=-60.0f; xF2=-60.0f; yS2=-80.0f; a1-=40.0f; b1-=40.0f; c1-=40.0f; d1-=40.0f; } } glEnd(); glutSwapBuffers(); glLoadIdentity(); } //this Function does any neede initialization on the rendering context void MyInit() { //black background glClearColor(1.0f,0.0f,0.0f,1.0f); //set drawing color to green glColor3f(0.0f,0.0f,0.0f); } void ChangeSize(int w, int h) { GLfloat nRange=100.0f; //prevent a divide by zero if(h==0) h=1; //set viewport to window dimensions glViewport(0,0,w,h); //reset projection matrix stack glMatrixMode(GL_PROJECTION); glLoadIdentity(); //establish clipping volume(left,right,bottom,top,near,far) if(w<=h) glOrtho(-nRange,nRange, -nRange*w/h,nRange*h/w,-nRange,nRange); else glOrtho(-nRange*w/h,nRange*w/h, -nRange,nRange,-nRange,nRange); //reset model view matrix stack glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("PONT EXMAPLE"); glutReshapeFunc(ChangeSize); glutDisplayFunc(DisplayScene); MyInit(); glutMainLoop(); return 0; }
Advertisement
I think you don't understand how word "static" works in c++

You declare variables like this, but you're changing them while drawing your checkboard.

	static GLfloat xF=-60.0; 	static GLfloat yS=-40.0;	static GLfloat xF1=-40.0; 	static GLfloat yS1=-60.0; 	static GLfloat a=80.0f; 	static GLfloat b=80.0f;	static GLfloat c=60.0f; 	static GLfloat d=60.0f; 	static GLfloat xFF=-80.0; 	static GLfloat ySS=-60.0;	static GLfloat xF2=-60.0; 	static GLfloat yS2=-80.0; 	static GLfloat a1=60.0f; 	static GLfloat b1=60.0f;	static GLfloat c1=40.0f; 	static GLfloat d1=40.0f; 


When the DisplayScene() is executed again, values of those variables have been changed from the previous frame

Change to this and everything will be ok

	 GLfloat xF=-60.0; 	 GLfloat yS=-40.0;	 GLfloat xF1=-40.0; 	 GLfloat yS1=-60.0; 	 GLfloat a=80.0f; 	 GLfloat b=80.0f;	 GLfloat c=60.0f; 	 GLfloat d=60.0f; 	 GLfloat xFF=-80.0; 	 GLfloat ySS=-60.0;	 GLfloat xF2=-60.0; 	 GLfloat yS2=-80.0; 	 GLfloat a1=60.0f; 	 GLfloat b1=60.0f;	 GLfloat c1=40.0f; 	 GLfloat d1=40.0f; 

This topic is closed to new replies.

Advertisement