UNKLAB FORUM

Forum Mahasiswa & Alumni Universitas Klabat
 
HomeFAQSearchMemberlistUsergroupsRegisterLog in
Bagi Guest atau user yang tidak terdaftar, mohon maaf karena ada beberapa thread tidak bisa diakses oleh guest, oleh karena itu, sebaiknya anda registrasi terlebih untuk bisa mengakses penuh forum ini. Baca dulu peraturan forum ini. Terima Kasih
Navigation
 Index
 Memberlist
 Profile
 FAQ
 Search
Search
 
 

Display results as :
 
Rechercher Advanced Search
Latest topics
» Lowongan Pekerjaan PT. PNM (Persero)
Wed Nov 08, 2017 7:01 pm by CLiFF

» .NET Programming
Tue Mar 15, 2011 6:49 pm by Marvin07

» Bagaimana Menginstal OS dari USB???
Thu Feb 10, 2011 9:55 pm by unaitech

» Automatic Installation BackTrack 3 Final | Dual Booting
Thu Feb 10, 2011 9:53 pm by unaitech

» simple hacking test
Thu Feb 10, 2011 7:38 pm by and213

» [tutor] How To Patch SQL Injection Bug
Thu Feb 10, 2011 9:52 am by unaitech

» what ur distro..?
Thu Feb 10, 2011 9:48 am by unaitech

» netcut source-code
Thu Feb 10, 2011 9:44 am by unaitech

» Ragnarok Online
Mon Jan 31, 2011 1:57 pm by Marvin07

FRIENDS
Ads

    No ads available.



    Share | 
     

     Program Membuat Garis dengan Mouse Pointer (Using Visual C++ with OpenGL).

    View previous topic View next topic Go down 
    AuthorMessage
    IT-hoo7
    Newbie
    Newbie


    Number of posts : 3
    Points : 0
    Registration date : 2008-09-14

    PostSubject: Program Membuat Garis dengan Mouse Pointer (Using Visual C++ with OpenGL).   Mon Sep 15, 2008 12:11 am

    Tolong dong bantuin buatnya gimana.....
    Algoritma or lebih bagus Source Code-nya..... Crying or Very sad Neutral Crying or Very sad
    Back to top Go down
    View user profile
    Anime
    Moderator
    Moderator
    avatar

    Male Number of posts : 35
    Age : 29
    Location : di atas tanah & di bawah langit
    Points : 0
    Registration date : 2008-06-07

    PostSubject: Re: Program Membuat Garis dengan Mouse Pointer (Using Visual C++ with OpenGL).   Sat Oct 11, 2008 11:25 pm

    // OpenGL_DrawingLine.cpp : Defines the entry point for the console application.
    //

    #include "stdafx.h"
    #include <GL/glut.h>

    int psize = 1; //Menentukan besar pixel
    int icoord = 0; //Menentukan apakah titik awal icoord = 0 atau titik akhir icoord = 1
    int wh = 400; //Tinggi layar window
    int ww = 400; //Lebar layar window

    struct Line
    {
    int x[2]; //Titik x1 dan x2
    int y[2]; //Titik y1 dan y2
    }line;

    void renderScene()
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glFlush();
    }

    void myMouseClick(int button, int state, int x, int y)
    {
    glColor3f(1.0,1.0,1.0);
    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)//jika mouse klik kiri
    {
    line.x[icoord] = x/psize;//tentukan x1 dan x2 untuk garis
    line.y[icoord] = (wh-y)/psize;//tentukan y1 dan y2 untuk garis
    if (icoord == 0)//titik awal
    {
    icoord++;
    }
    else
    {
    glBegin(GL_LINES);//hubungkan titik awal dan titik akhir
    glVertex2i(line.x[0],line.y[0]);
    glVertex2i(line.x[1],line.y[1]);
    glEnd();
    glFlush();
    icoord = 0; //set index untuk x dan y menjadi 0 lagi
    }
    }
    }

    void reshape(int neww, int newh)
    {
    ww = neww;
    wh = newh;
    glViewport(0,0,ww,wh);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.,(GLdouble)ww/psize,0.,(GLdouble)wh/psize); /* ensure aspect ratio */
    //glutOrtho2D(left,right,bottom,top)
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    void myMotion(int x,int y)
    {
    //catch mouse position and draw line while mouse left button is click and hold (drag)
    line.x[icoord] = x/psize;
    line.y[icoord] = (wh-y)/psize;
    if (icoord == 0)//titik awal
    {
    icoord++;
    }
    else
    {
    glBegin(GL_LINES);
    glVertex2i(line.x[0],line.y[0]);
    glVertex2i(line.x[1],line.y[1]);
    glEnd();
    glFlush();
    icoord = 0;
    }
    }

    int main(int argc, char* argv[])
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(400, 400);
    glutCreateWindow("Drawing Line");
    glutDisplayFunc(renderScene);
    glutMouseFunc(myMouseClick);
    glutMotionFunc(myMotion);
    glutReshapeFunc(reshape);
    glutMainLoop();

    return 0;
    }
    Back to top Go down
    View user profile
     
    Program Membuat Garis dengan Mouse Pointer (Using Visual C++ with OpenGL).
    View previous topic View next topic Back to top 
    Page 1 of 1
     Similar topics
    -
    » Mickey Mouse Praise and Worship
    » 2012 MEPI Student Leaders Program
    » "Bank" program called "my" to serve small and medium-sized enterprises
    » Sheiko program
    » The Passive Voice : A Visual Lesson

    Permissions in this forum:You cannot reply to topics in this forum
    UNKLAB FORUM :: KLABAT UNIVERSITY :: Computer Science Faculty :: Programming :: C , C++ and C#-
    Jump to: