PDA

View Full Version : Making a slider in openGL



g0rush
11-21-2016, 02:24 PM
Hey I'm a complete openGL noob. I'm attempting to make a simple slider. I have the following:


void display(){

glClear(GL_COLOR_BUFFER_BIT);
glLineWidth((GLfloat)2);
glColor3f(0, 0, 0);

glBegin(GL_LINES);

glVertex2i(100, (height - 50 - 255));
glVertex2i(100, (height - 50));
glEnd();

glBegin(GL_QUADS);

glColor3f(1, 0, 0);

glVertex2i(90, redY - 5);
glVertex2i(90, redY + 5);
glVertex2i(110, redY + 5);
glVertex2i(110, redY - 5);

glEnd();
glutSwapBuffers();
}

void mouse(int button, int state, int x, int y){
switch (button){
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN){
if (x >= 90 && x <= 110 && y >= redY - 5 && y <= redY + 5){
ruberbanding = true;
}
}
else if (state == GLUT_UP){
ruberbanding = false;
}
glutPostRedisplay();
}
}

void motion(int x, int y){
if (ruberbanding && y <= 555 && y >= 255){
redY = y;
glutPostRedisplay();
}
}


the display function is listed as my display callback. Why doesn't this work? I think I may have misunderstood something along the way.

john_connor
11-21-2016, 02:50 PM
the window is only of size [-1; +1] x [-1; +1]
i think your vertex coordinates are too high