Advertisement

09.18.2008 at 04:00PM PDT, ID: 23744313
[x]
Attachment Details

OpenGL -- "void(move)" function

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2
I'm taking a class in OpenGL.  We've been giving some examples files that required modification.

The program below draws a square.   I've already replaced the "lines" with "square" (mouse function).   I've also modified the "move()" function.    Although the program compiles/builds fine, the move() function doesn't seem to work properly.  

With the commented out move() function, it draws the square but it is using lines.   It is supposed to already draw a square when dragging/moving the mouse.

What am I missing?  

EEH
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
#include <stdlib.h>
#include <GL/glut.h>
 
float xm, ym, xmm, ymm;
float width = 500, height = 500;
int first = 0;
 
 
void mouse(int btn, int state, int x, int y)
{
	if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
	{
		xm = x / width;
		ym = (height - y) / height;
		glColor3f(0.0, 0.0, 1.0);
		glLogicOp(GL_XOR);
		first = 0;
	}
	if (btn == GLUT_LEFT_BUTTON && state == GLUT_UP)
	{
		glRectf(xm, ym, xmm, ymm);
		glFlush();
		glColor3f(0.0, 1.0, 0.0);
		xmm = x / width;
		ymm = (height - y) / height;
		glLogicOp(GL_COPY);
		glRectf(xm, ym, xmm, ymm);
		glFlush();
	}
}
 
void myReshape(int w, int h)
{
   	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, 1, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
 
   	glViewport(0, 0, w, h);
	width = w; height = h;
}
 
 
 
 
//void move(int x, int y)
//{
//	if (first == 1)
//	{
//		glBegin(GL_LINES);
//			glVertex2f(xm, ym);
//			glVertex2f(xmm, ymm);
//		glEnd();
//		glutSwapBuffers();
//		glFlush();
//	}
//
//	xmm = x / width;
//	ymm = (height - y) / height;
//	glBegin(GL_LINES);
//		glVertex2f(xm, ym);
//		glVertex2f(xmm, ymm);
//	glEnd();
//	glutSwapBuffers ();
//	glFlush();
//	first = 1;
//}
 
 
void move(int x, int y)
{
	if (first == 1)
	{
		glRectf(xm, ym, xmm, ymm);
		glFlush();
	}
	xmm = x / width;
    ymm = (height - y) / height;
	glRectf(xm, ym, xmm, ymm);
	glFlush();
	first = 1;
}
 
 
void myinit() 
{
    glClearColor (0.0, 0.0, 0.0, 1.0);
}
 
/* display callback required by GLUT */
 
void display() 
{
	glClear(GL_COLOR_BUFFER_BIT);
	glutSwapBuffers();
	glFlush();
}
 
int main(int argc, char** argv) 
{
    glutInit(&argc,argv);
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowPosition(100, 100);
	glutInitWindowSize(width, height);
    glutCreateWindow("Rubberband");
    myinit ();	
	glEnable(GL_COLOR_LOGIC_OP);
    glutReshapeFunc (myReshape);
    glutMouseFunc (mouse);
    glutMotionFunc(move);
    glutDisplayFunc(display);
    glutMainLoop();
}
Answered By: itsmeandnobodyelse
Expert Since: 10/02/2003
Accepted Solutions: 2581
Computer Expertise: Guru
itsmeandnobodyelse has been an Expert for 5 years 3 months, during which he has posted 11196 comments and answered 2581 questions. itsmeandnobodyelse is just one of 71 experts in the OpenGL Graphics & Game Programming Zone. 1 expert collaborated on this answer, which was graded an "A" by the asker.
 
 
20081119-EE-VQP-47 / EE_QW_2_20070628