MrDoomMaster
May 30th, 2004, 08:35 PM
Hey guys, when I run my program it doesn't exactly refresh the client window rectangle!
I have attached a screenshot of what it looks like. How can I make the background black?
Marc G
May 31st, 2004, 04:28 AM
Could you post your drawing function?
wien
May 31st, 2004, 11:55 AM
You are probably forgetting to clear the framebuffer before you render.// Set clear color and clear depth:
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
// Clear Screen And Depth Buffer:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Render here...
MrDoomMaster
May 31st, 2004, 02:59 PM
Here is the code of my program:
//Robert Dailey
//1031
//5-26-04
//Meander Border
//--Header-Files--------------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>
#include "canvas.h"
//----------------------------------
//--Enumerations--------------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
enum Direction {Left, Right};
//----------------------------------
//--Function-Prototypes-------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
void Initialization();
void cbDraw();
void DrawMeander(float, float);
void RotateMeander(Direction);
//----------------------------------
//--Global-Variables----------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Canvas Meander1(401, 401, "Meander");
/*-------------------------*/
GLint WindowX = 401;
GLint WindowY = 401;
int DegreeArray[8] = {0, 90, 180, 270, 180, 90, 0, 270}; //Map of turns for pattern
int DistanceArray[8] = {30, 30, 10, 20, 10, 30, 30, 40}; //Map of distance of lines in pattern
int StartingX[4] = {320, 40 , 80, 360}; //X axis when starting new side
int StartingY[4] = {360, 320, 40, 80}; //Y axis when starting new side
//----------------------------------
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(WindowX, WindowY);
glutInitWindowPosition(200, 200);
glutCreateWindow("Meander Border");
glutDisplayFunc(cbDraw);
Initialization();
glutMainLoop();
system("pause");
return 0; }
/****************************\
| Function Bodies |
\****************************/
void Initialization() {
glClearColor(0.75, 0.75, 1.0, 0.0);
glColor3f(0.0f, 0.0f, 1.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, WindowX, 0, WindowY); }
//========================================
void cbDraw() {
//--cbDraw-Declarations---------------
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
float DrawX = 0;
float DrawY = 0;
//------------------------------------
for(int i = 0; i < 4; i++) {
DrawX = StartingX[i]; //Set Starting X value for next side
DrawY = StartingY[i]; //Set Starting Y value for next side
for(int ii = 0; ii < 8; ii++) {
DrawMeander(DrawX, DrawY);
switch(i) {
case 0: //Top Right >> Top Left
DrawX -= 40;
break;
case 1: //Top Left >> Bottom Left
DrawY -= 40;
break;
case 2: //Bottom Left >> Bottom Right
DrawX += 40;
break;
case 3: //Bottom Right >> Top Right
DrawY += 40; } }
RotateMeander(Left); } //Rotate Meander to the left for next side
glFlush(); }
//========================================
void DrawMeander(float Xval, float Yval) {
Meander1.moveTo(Xval, Yval); //
for(int i = 0; i < 8; i++) {
Meander1.turnTo(DegreeArray[i]);
Meander1.forward(DistanceArray[i], true); } }
//========================================
void RotateMeander(Direction Rotation) {
switch(Rotation) {
case Left:
for(int i = 0; i < 8; i++)
if(DegreeArray[i] == 270)
DegreeArray[i] = 0;
else
DegreeArray[i] += 90;
break;
case Right:
for(int i = 0; i < 8; i++)
if(DegreeArray[i] == 0)
DegreeArray[i] = 270;
else
DegreeArray[i] -= 90; } }
sorry that it's long lol
wien
May 31st, 2004, 03:53 PM
As I said... You need to clear the framebuffer. Put a glClear at the beginning of the cbDraw function.