Click here to Skip to main content
15,881,630 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys
I have a window on which i display my figure(stick). I have a sperate code that is quite basic and it draws some stars on teh top left corner of a window now basically i am trying to merge two things but i am getting a a window with only figure in it
C++
void myDisplay(void){
      Body b;

	glutSwapBuffers();



	glClearColor(0.4, 1, 1, 0.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glLoadIdentity();
	glColor3f(0.0, 0.0, 0.0);
	glColor3ub(0, 0, 0);
	b.drawCyborg();
	glutSwapBuffers();
	glClear(GL_COLOR_BUFFER_BIT);
	DrawStars();
	glFlush();
}


and this is my int main
C++
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT);
glutInitWindowPosition(50, 50);
glutCreateWindow("window figure with stars");
myInit();


glutDisplayFunc(myDisplay);
glutReshapeFunc(myReshape);
//glutReshapeFunc(handleResize);
glutMotionFunc(pressed_mouse);
glutMouseFunc(mouse);
glutCreateMenu(menu);
glutAddMenuEntry("view_hor/vert", 0);
glutAddMenuEntry("view_zoom_in/out", 1);
glutAddMenuEntry("view_lft-rgt/up-dow", 2);
glutAddMenuEntry("quit", 3);
glutAttachMenu(GLUT_MIDDLE_BUTTON);
glutKeyboardFunc(keyboard);
redisplay_all();
glutMainLoop();

now this work fine now problem is it does draw stars as i have called my function drawStars(); in the end. However it draws figure correctly. Any guesses where i am missing the trick. I am quite new so pardon my basic questions
Posted
Comments
enhzflep 25-Nov-14 4:55am    
Your myDisplay function looks mighty suspicious to me.

I suggest making the following changes.

1) Call glClearColor and glClear first.
2) Call g.Draw and DrawStars next.
3) Finally, glutSwapBuffers

If I recall correctly, glSwapBuffers puts the computed picture on the screen, so you only need to call that once. Also, anything drawn after calling this will not be visible - hence you see a stick figure but not the stars.
Santhosh G_ 27-Nov-14 8:35am    
Please post details inside b.drawCyborg() and DrawStars(). It is better to follow steps mentioned by enhzflep. Please avoid first glutSwapBuffer call from myDispkay and call it after all drawings[b.drawCyborg() and DrawStars()].

1) Call glClearColor and glClear first.
2) Call g.Draw and DrawStars next.
3) Finally, glutSwapBuffers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900