Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: how can I draw more than one line??

  1. #1
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    how can I draw more than one line??

    hi every body

    i implment small program for draw line

    the user specify the first and end point and he can use right button to show menu cang color ,think or pattren


    the code work proprtly but

    i want allowed to user draw more than one line
    and change the proprites of line independent way than the others

    how i can do that?


    this is my code

    #include <gl/glut.h>
    float red=1.0,blue=0.0,green=0.0,width=1;
    int con=0,x1=0,x2=0,y1=0,y2=0,patt=0;

    //***********
    void selectcolor (int selection )
    { switch (selection)
    { case 1: red=1.0; blue=0.0;green=1.0;
    break;
    case 2: red=0.0 ; blue=0.0; green=1.0;
    break;
    case 3: red=0.0;blue=1.0;green=0.0;
    break;}
    glutPostRedisplay();}

    //**************
    void selectionstipp (int selectstripp)
    { patt=selectstripp;
    glutPostRedisplay();}

    //*************
    void selectwidth(int selectwidth)
    {switch (selectwidth)
    {case 7:width=7;
    break;
    case 8: width=9;
    break;
    case 9: width=11;
    break;
    }
    glutPostRedisplay();}
    //******************* main menu
    void select (int selectmain)
    {switch(selectmain)
    {case 0:exit(0);}
    glutPostRedisplay();}
    //************************
    void reshape(int w,int h)
    {glViewport(0,0,300,300);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0,300,0.0,300.0);
    }

    //*****************
    void display (void)
    {glClear(GL_COLOR_BUFFER_BIT);
    glEnable(GL_LINE_STIPPLE);
    switch(patt)
    {case 4:
    glLineStipple(1,0xFF00);//dash
    break;
    case 5:glLineStipple(1,0xE4E4);//dot dash
    break;
    case 6: glLineStipple(1,0xFFFF);//SOLID
    break;}
    glLineWidth(width);

    //draw line
    glBegin(GL_LINES);
    glColor3f(red,blue,green);
    glVertex2i(x1,y1);
    glVertex2i(x2,y2);
    glEnd();

    glDisable(GL_LINE_STIPPLE);
    glFlush();
    }

    void init (void)
    {glClearColor(1.0,1.0,1.0,0);
    }
    //******************
    void mouse (int botton ,int state ,int x , int y)
    {
    if( (botton==GLUT_LEFT_BOTTON)&&(state==GLUT_DOWN))
    if( con==0)
    { x1=x;x2=x;y1=300-y;y2=300-y;con=con+1;}
    else {x2=x;y2=300-y; con=con-1;}

    glutPostRedisplay();}

    //******************
    int main (int argc , char **argv)
    { glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
    //CREAT WINDOW
    glutInitWindowSize(300,300);
    glutInitWindowPosition(0,0);
    glutCreateWindow("LINE STIPPLE");

    int menucolor=glutCreateMenu(selectcolor);//submenu for color
    glutAddMenuEntry("RED",1);
    glutAddMenuEntry("BLUE",2);
    glutAddMenuEntry("GREEN",3 );

    int menustrippt=glutCreateMenu(selectionstipp);
    glutAddMenuEntry("DASH",4);
    glutAddMenuEntry("DOT_DASH",5);
    glutAddMenuEntry("SOLID",6);

    int menuwidth=glutCreateMenu(selectwidth);

    glutAddMenuEntry("WIDTH 1",7);
    glutAddMenuEntry("WIDTH",;
    glutAddMenuEntry("WIDTH",9);

    glutCreateMenu(select);
    glutAddSubMenu("COLOR",menucolor);
    glutAddSubMenu("pattren",menustrippt);
    glutAddSubMenu("withness",menuwidth);
    glutAddMenuEntry("QUIT",0);

    glutAttachMenu(GLUT_RIGHT_BOTTON);
    glutMouseFunc(mouse);
    init();
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;}


    ===============
    my program when user want drae another line the first line earse


    regards
    MOON_GIRL


    [This message has been edited by MOON-GIRL (edited 12-02-2002).]
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  2. #2
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: how can I draw more than one line??

    pleeeeeeeeeeeeeeeeeeeeese any body help me
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2002
    Location
    York, UK
    Posts
    128

    Re: how can I draw more than one line??

    The problem you are having is that you are misunderstanding how OpenGL renders. Remember that everything is drawn each time you request a redisplay. So, in your case you clear the colour buffer and then draw the line again, but with the new values!

    What you need to do (as an example) is to store the coordinates of each line as they are generated let's say in two arrays xv, and yv. You keep a count of how many lines you have stored. You may also want to store other attributes of each line as well in other arrays.

    Then in your display function, you run through these arrays drawing lines, up to the number of lines you have stored.

    Of course, this is a VERY simple case.

    You will learn that as you go on with OpenGL programming (and graphics programming in general) the data to be displayed on screen is held in a "scene description". There are various ways this is done and will depend of the application in question. But, in the end, the actual data drawn on screen will be done via processing of the scene description.

    Hope this helps,

    Good luck - an assignment I guess?

    Rob.

  4. #4
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: how can I draw more than one line??

    welcome Rob


    its true I mis understand open gl but I try
    and a wait help from any body


    =================
    when i dont know how lines user want draw I use linked list?for example


    and the node contine structured or not allowed??


    regards
    Moon_Girl
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  5. #5
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: how can I draw more than one line??

    CAN you give me any complete code
    i want see how its work


    regards
    Moon_Girl
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    20

    Re: how can I draw more than one line??

    I just got done with a 2D drawing app in windows. I did exactly what the previous person said. here is some sample code from my programs "OnDraw" function:

    Code :
    for (int i=0; i < pDoc->NumLines; i++)
    	{
    		MakePen(pDoc->LineWidth[i], pDoc->LineColor[i]);
    		pDC->SelectObject(&amp;m_ThePen);
    		pDC->MoveTo(pDoc->FLinePoint[i]);
    		pDC->LineTo(pDoc->LLinePoint[i]);
    	}
    you see, I do a for loop for how many lines there are. then make a pen that was used (width, color) when line[i] was drawn. then draw it from the x points that were stored in the array, and y points that were stored in another array. all of these arrays are updated with the right properties once the user draws a line.

    [This message has been edited by KenR7A (edited 12-03-2002).]

  7. #7
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: how can I draw more than one line??

    No time to write a whole program, but maybe this will give you an idea.

    typedef struct
    {
    int x1, y1; //Start of line
    int x2, y2; //End of line
    glFloat color[3];
    }LINE_STRUCT;


    LINE_STRUCT lines[5]; // Where 5 is the number of lines we can store in our structure, could be a larger number


    if (mouse_down)
    {
    lines[line_count].x1 = mouse_x;
    lines[line_count].y1 = mouse_y;
    }

    if (mouse_up)
    {
    lines[line_count].x2 = mouse_x;
    lines[line_count].y2 = mouse_y;
    line_count++;
    }


    display()
    {


    for(i=0, i < line_count, i++)
    {
    glColor3fv(lines[i].color)
    glBegin(GL_LINE);
    glVertex2i(lines[i].x1, lines[i].y1);
    glVertex2i(lines[i].x2, lines[i].y2);
    glEnd();
    }


    Originally posted by MOON-GIRL:
    CAN you give me any complete code
    i want see how its work


    regards
    Moon_Girl

  8. #8
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: how can I draw more than one line??

    HI;

    welcome KenR7A

    are use pointer?
    can i see ahole program of "OnDraw"
    ==========

    welcome nexusone

    i understand this code

    but when i dont how line i need
    i want user enter as its like


    CAN EXPLINE WHAT IS THIS DO
    glfloat color[3]


    thank you every boady
    and i wait you


    Moon_Girl




    [This message has been edited by MOON-GIRL (edited 12-03-2002).]
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  9. #9
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    20

    Re: how can I draw more than one line??

    its the pointer to the DOC class in my 2D drawing program. its no code to put in a GL project, I was just showing you what you had to do in order for your app to remember what lines were drawn and how to re-draw them when you need to. just an idea, not an actual solution.

  10. #10
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: how can I draw more than one line??

    welcome


    thank you

    but i still have problem with my program

    Some person also give me coding using list until this moment dosnt work


    regards
    Moon_Girl
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

Page 1 of 2 12 LastLast

Similar Threads

  1. how to draw a line ?
    By Coming from afar in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-20-2014, 03:08 PM
  2. draw line, line-size ... opengl 3.3 ?
    By CarstenT in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-28-2014, 08:19 AM
  3. always draw a black line
    By kewuwsi in forum OpenGL: GLSL
    Replies: 5
    Last Post: 10-03-2007, 07:53 AM
  4. Draw Line
    By IG in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-18-2006, 07:57 AM
  5. about draw 2d line
    By Barbary in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 03-01-2005, 11:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean