Using OpenGL in C++ //reference for creating the sliders #include #include #incl
ID: 3865708 • Letter: U
Question
Using OpenGL in C++
//reference for creating the sliders
#include
#include
#include
#include
GLint vert[100][2];
int width =400, height=600, n=0,
type = GL_LINE_STRIP, v;
bool rubberbanding = false, antialiasing = false;
void display(){ // display function
glClear(GL_COLOR_BUFFER_BIT);
if (n==1 && (type ==GL_LINE_STRIP || type == GL_LINE_LOOP)) {
glBegin(GL_POINTS);
glVertex2iv(vert[0]);
glEnd();
}
glBegin(type);
for (int i=0; i
glEnd();
glutSwapBuffers();
}
void keyboard(unsigned char key, int x, int y){
switch (key) {
case 'a': antialiasing = !antialiasing;
if (antialiasing) {
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
}else{
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
break;
case 'c': n=0; break;
case 'l': type=GL_LINE_STRIP; break;
case 'p': type= GL_LINE_LOOP; break;
case 'v': type = GL_POINTS; break;
}
glutPostRedisplay();
}
int findVertex(int x, int y){
int dx, dy;
for (int i=0; i
dx=vert[i][0]-x;
dy=vert[i][1]-y;
if (dx*dy + dy*dy < 16) return i;
}
return -1;
}
void mouse(int button, int state, int x, int y){
switch (button) {
case GLUT_LEFT_BUTTON:
if (state == GLUT_DOWN) {
v=n++;
vert[v][0]=x;
vert[v][1]=height-1-y;
rubberbanding = true;
glutPostRedisplay();
}
else rubberbanding = false;
break;
case GLUT_RIGHT_BUTTON:
if (state == GLUT_DOWN && (v=findVertex(x, height-1-y))!= -1){
if (glutGetModifiers()==GLUT_ACTIVE_CTRL) {
for (int i =v; i
vert[i][0]=vert[i+1][0];
vert[i][1]=vert[i+1][1];
}
n--;
}else{
vert[v][0]=x;
vert[v][1]=height-1-y;
rubberbanding=true;
}
glutPostRedisplay();
}
else rubberbanding= false;
break;
}
}
void motion(int x, int y){
if (rubberbanding) {
vert[v][0]=x;
vert[v][1]=height-1-y;
glutPostRedisplay();
}
}
int main(int argc, char** argv) { //main function
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(50, 100);
glutCreateWindow("edit polygons");
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1, 1, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutMainLoop();
}
Write an interactive color mixer that allows the user to experiment with different combinations of the RGB primaries. The display window (see sketch below) should have three sliders that are used to adjust the value (between 0 and 255) of the primaries, square region showing the mixed effect of the three primaries, and a rectangular region showing the effect of linear interpolation between the color of its left edge and the color of ifs right edge.Explanation / Answer
ANSWER::
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.