PDA

View Full Version : OPEN GL HELP PLZ



alphanumeric123
03-21-2012, 11:09 AM
Hello everybody i have an problem that i dont know how to solve,
i have to create a free hand drawing tool on OpenGl C++ can anybody of you tell me how to do this bcz i dont have any idea.

Beast Regards

menzel
03-21-2012, 12:22 PM
There are lots of ways to do that and lots of possible problems. You should be more specific with your question. Do you even know how to code in C++? Do you know OpenGL? Do you have decided on a OS and windowing toolkit?

alphanumeric123
03-21-2012, 03:40 PM
Dear now i have created program on c++ for making points, i can send you the code.
Here is the code:


#include<gl\glut.h>

const int screenWidth=800;
const int screenHeight=600;

void Init()
{
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
gluOrtho2D(0.0,(GLdouble)screenWidth,0.0,(GLdouble )screenHeight);
glViewport(0,0,screenWidth,screenHeight);
}

void Display()
{
glColor3f(0.0,0.0,1.0);
glPointSize(6.0);
glFlush();

}

//callback mouse function
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
if(button==GLUT_LEFT_BUTTON)
{
glBegin(GL_POINTS);
glVertex2i(x,screenHeight-y);

glEnd();
}
else if(button==GLUT_RIGHT_BUTTON)
glClear(GL_COLOR_BUFFER_BIT);
}
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(screenWidth,screenHeight);
glutInitWindowPosition(100,100);
glutCreateWindow("Katerkenedshi Dinamik");
glutMouseFunc(mouse);
glutDisplayFunc(Display);
Init();
glutMainLoop();
return 0;
}

And from this code i want to make free hand draw tool, if i am clearly thats the point, so if you can tell me what to do to draw free lines.

Best Regards

tonyo_au
03-21-2012, 09:21 PM
First, you need to save the mouse down x,y in some array in the mouse handler.

Then in the Display handler, loop through this list and display the points.

Something like this



glColor3f(0.0,0.0,1.0);
glPointSize(6.0);

glBegin(GL_POINTS);
for (int i = 0; i < nbr_of_points; i++)
glVertex2i(x[i],y[i]);
glEnd();


I also think there is a limit on the maximum value for glPointSize.

alphanumeric123
03-22-2012, 03:30 AM
i tried but it doesnt work, i dont know what is wront and i dont know if im clear but the point is that i want to free hand draw with this program, and if somebody can try this and then send me all the code, bcz im trying while 2 weeks or more.

Best Regards

alphanumeric123
03-22-2012, 08:44 AM
anyone plz it is urgent

BionicBytes
03-22-2012, 10:00 AM
generally speaking people here will not do home work assignments for you.

alphanumeric123
03-22-2012, 10:40 AM
i know but im not asking to you to do all my assignments thats a problem that i cannot fix, and that is a forum that can tell me how to do, if you cannot do it its not problem, then for what is this forum
???

menzel
03-22-2012, 11:57 AM
This forum is for general discussion about OpenGL related topics and also about helping each other with specific OpenGL problems.

We can point you in the right direction if you ask questions about GL, but we will not write full programs for you. tonyo_au told you how you could tackle the problem of drawing connected lines, telling us that it's not working (without showing how you tried it) and asking for someone to solve your homework is not the reaction that motivates any of us investing time on this...

Also, you haven't answered my questions, we don't know how experienced you are with C/C++ or OpenGL (well we could derive that from your code, but still, you don't make anything to help us with helping you...)

alphanumeric123
03-22-2012, 12:30 PM
i tried with this code:


glBegin(GL_POINTS);
for (int i = 0; i < 30; i++)

glVertex2i(x[i],y[i]);

glEnd();


it shows up to me : expression must have pointer-to-object type.
i have tried something else with

glRecti(x,y,x+brush,y+brush); where brush is a GLint but it doesnt work, thats the problem my dear.

menzel
03-22-2012, 04:37 PM
Without knowing the datatypes of x and y it's hard to tell what the problem is (the error 'expression must have pointer-to-object type' was a compile-time error at the line glVertex2i(x[i],y[i]); ?)

tonyo_au
03-22-2012, 05:29 PM
expression must have pointer-to-object type.


Is this a compiler error or runtime error?

alphanumeric123
03-23-2012, 07:17 AM
no it was a compiler error and x and y are int that is the mouse click code:


void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
if(button==GLUT_LEFT_BUTTON)
{
glBegin(GL_POINTS);
for (int i = 0; i < 30; i++)
glVertex2i(x,y);
glEnd();
}

menzel
03-23-2012, 12:43 PM
In the code you posted now you're drawing the same point 30 times but that is not the code you showed us before. You can't use an int as an array obviously...

alphanumeric123
03-23-2012, 01:01 PM
void mouse(int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
if(button==GLUT_LEFT_BUTTON)
{
glBegin(GL_POINTS);
for (int i = 0; i < 30; i++)
glVertex2i(x[i],y[i]);
glEnd();
}


Dear that is only the mouse function, and it is with the code that you send to me, the glVertex2i(x[i],y[i]); is youre code, what should i change to make free hand drawing lines..i dont know if you clearly understand my point..

Best Regards

tonyo_au
03-23-2012, 07:18 PM
Your problem is you don't seem to understand how to program in C++. Try looking up how to use arrays in C++ then re-read my suggestions for the OpenGL code.

What language do you normally program in?