PDA

View Full Version : probably something really dumb...



shrunkenhed
01-27-2003, 04:33 PM
Hi, I'm hacing trouble with this program that i have. what it should do is create a bunch of different color boxes using the QUAD_STRIP for my polygons:
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glut.h>
#include <math.h>


void RenderScene()
{

GLfloat x,y;
x = x + 10;
y = y + 10;
int cPivot = 1;

glDisable(GL_CULL_FACE);
if(( cPivot %2) == 0)
glColor3f(1.0f, 0.0f, 0.0f);

else

glColor3f(0.0f, 1.0f, 0.0f);

glClear(GL_COLOR_BUFFER_BIT);


glColor3f(.03f, 1.f, 0.0f);
glBegin(GL_QUAD_STRIP);
//First quad
glVertex3f(0.0f, 0.0f, 0.0f);
glVertex3f(0.0f, 10.0f, 0.0f);
glVertex3f(10.0f, 0.0f, 0.0f);
glVertex3f(10.0f, 10.0f, 0.0f);




//Second quad
glVertex2f(x, y);
glVertex2f(x, y);
glEnd();

glFlush();
glutSwapBuffers();

}
void TimerFunc(int value)
{
glutPostRedisplay();
glutTimerFunc(100, TimerFunc, 1);

}

void ChangeSize(int w, int h)
{
GLfloat nRange = 200.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*h/w, 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();
}
void SetupRC()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glColor3f(0.0f, 1.0f, 0.0f);
glFrontFace(GL_CW);
glShadeModel(GL_FLAT);

}
void main(void)
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow("simple ****");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
glutTimerFunc(100, TimerFunc, 1);

SetupRC();
glutMainLoop();
}

If you can help that'd be great

mikael_aronsson
01-27-2003, 10:21 PM
Hi !

Maybe you could explains what does happen when you run the code ?

I havn't tried it, but this part looks a bit odd to me...

//Second quad
glVertex2f(x, y);
glVertex2f(x, y);
glEnd();

Mikael

fringe
01-28-2003, 12:24 AM
Also you need to init x and y att the moment they have no intial value, this could be bad

fringe