yakinlah bahwa setiap langkah besar selalu diawali dengan langkah kecil yang konsisten

Kamis, 07 Juni 2012

Project OpenGL menggambar Objek 2D

Diposting oleh Rissa di 07.15
Sub INISIALISASI()
'========== Inisialisasi ==========
    EnableOpenGL Me.hDC

    hrc = wglCreateContext(hDC)
    wglMakeCurrent hDC, hrc
   
    'Inisilisasi Koordinat D2
    xmin = -20: ymin = -20
    xmax = 20: ymax = 20
    gluOrtho2D xmin, xmax, ymin, ymax
   
    glClearColor 0, 0, 0, 0
    glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
    glClear clrColorBufferBit
    glMatrixMode GL_PROJECTION
    glLoadIdentity
End Sub

Sub Bersihkan_Layar()
    glClearColor 0, 0, 0, 0
    glClear GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT
End Sub

Sub Tampilkan()
    glFlush
    SwapBuffers Me.hDC
End Sub

Private Sub Command1_Click()
    Call INISIALISASI
End Sub

Private Sub Command2_Click()
Dim x As Single, y As GLfloat
Dim rad2Derajad As Single, R As Single
    rad2Derajad = 3.14 / 180
    R = 5
    Call Bersihkan_Layar
   
    glEnd
     '======================
             'frame kanan
    glBegin bmQuads
    glColor3f 1, 0, 0
           glVertex2f 20, 20
           glVertex2f 19, 20
           glVertex2f 19, -20
           glVertex2f 20, -20
    glEnd
        '======================
            'frame bawah
    glBegin bmQuads
    glColor3f 1, 0, 0
           glVertex2f 20, -19
           glVertex2f 20, -20
           glVertex2f -20, -20
           glVertex2f -20, -19
    glEnd
  
    '==================
             'frame atas
    glBegin bmQuads
    glColor3f 1, 0, 0
           glVertex2f -20, 20
           glVertex2f -20, 19
           glVertex2f 20, 19
           glVertex2f 20, 20
    glEnd
  
    '==================
        'frame kiri
    glBegin bmQuads
    glColor3f 1, 0, 0
           glVertex2f -20, 20
           glVertex2f -19, 20
           glVertex2f -19, -20
           glVertex2f -20, -20
    glEnd
  
    '==================
     'lingkaran hiasan ijo
    glBegin bmPolygon
    glColor3f 0, 1, 0
    For teta = 1 To 360
        x = 7 * Cos(teta * rad2Derajad)
        y = 7 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y - 20
    Next
    glEnd
   
    '==============
    'lingkaran hiasan kuning
    glBegin bmPolygon
    glColor3f 1, 1, 0
    For teta = 1 To 360
        x = 5 * Cos(teta * rad2Derajad)
        y = 5 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y - 20
    Next
    glEnd
   
   
     '==============
         'lingkaran hiasan merah
    glBegin bmPolygon
    glColor3f 1, 0, 0
    For teta = 1 To 360
        x = 3 * Cos(teta * rad2Derajad)
        y = 3 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y - 20
    Next
    glEnd
   
    '==================
     'lingkaran hiasan ijo
    glBegin bmPolygon
    glColor3f 0, 1, 0
    For teta = 1 To 360
        x = 7 * Cos(teta * rad2Derajad)
        y = 7 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y - 20
    Next
    glEnd
   
    '==============
    'lingkaran hiasan kuning
    glBegin bmPolygon
    glColor3f 1, 1, 0
    For teta = 1 To 360
        x = 5 * Cos(teta * rad2Derajad)
        y = 5 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y - 20
    Next
    glEnd
   
   
     '==============
         'lingkaran hiasan merah
    glBegin bmPolygon
    glColor3f 1, 0, 0
    For teta = 1 To 360
        x = 3 * Cos(teta * rad2Derajad)
        y = 3 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y - 20
    Next
    glEnd
   
    '==================
     'lingkaran hiasan ijo
    glBegin bmPolygon
    glColor3f 0, 1, 0
    For teta = 1 To 360
        x = 7 * Cos(teta * rad2Derajad)
        y = 7 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y + 20
    Next
    glEnd
   
    '==============
    'lingkaran hiasan kuning
    glBegin bmPolygon
    glColor3f 1, 1, 0
    For teta = 1 To 360
        x = 5 * Cos(teta * rad2Derajad)
        y = 5 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y + 20
    Next
    glEnd
   
   
     '==============
         'lingkaran hiasan merah
    glBegin bmPolygon
    glColor3f 1, 0, 0
    For teta = 1 To 360
        x = 3 * Cos(teta * rad2Derajad)
        y = 3 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 20, y + 20
    Next
    glEnd
   
     '==============
    
        'lingkaran hiasan ijo
    glBegin bmPolygon
    glColor3f 0, 1, 0
    For teta = 180 To 360
        x = 7 * Cos(teta * rad2Derajad)
        y = 7 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y + 20
    Next
    glEnd
   
     '==============
    'lingkaran hiasan kuning
    glBegin bmPolygon
    glColor3f 1, 1, 0
    For teta = 180 To 360
        x = 5 * Cos(teta * rad2Derajad)
        y = 5 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y + 20
    Next
    glEnd
   
     '==============
    'lingkaran hiasan merah
    glBegin bmPolygon
    glColor3f 1, 0, 0
    For teta = 180 To 360
        x = 3 * Cos(teta * rad2Derajad)
        y = 3 * Sin(teta * rad2Derajad)
       
        glVertex2f x + 20, y + 20
    Next
    glEnd
   

    '==============
        'lingkaran SOLID bayangan bulan
    glBegin bmPolygon
    glColor3f 1, 0.4, 0
    For teta = 1 To 360
        x = 16.5 * Cos(teta * rad2Derajad)
        y = 16.5 * Sin(teta * rad2Derajad)
       
        glVertex2f x, y
    Next
    glEnd
   
    '==============
    'lingkaran SOLID 1 bulan
    glBegin bmPolygon
    glColor3f 1, 1, 0
    For teta = 1 To 360
        x = 16 * Cos(teta * rad2Derajad)
        y = 16 * Sin(teta * rad2Derajad)
       
        glVertex2f x, y
    Next
    glEnd
   
    '==============
    'lingkaran SOLID 2 bulan
    glBegin bmPolygon
    glColor3f 0, 0, 0
    For teta = 1 To 360
        x = 12 * Cos(teta * rad2Derajad)
        y = 12 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 3.5, y + 3.5
    Next
    glEnd
   
     '==============
        'kaki kanan
    glBegin bmQuads
    glColor3f 0.74, 0, 1
           glVertex2f -2, -2
           glVertex2f 4, -8
           glVertex2f 2, -10
           glVertex2f -4, -4
 
    glEnd
    '======================
    'kaki kiri
    glBegin bmQuads
    glColor3f 0.74, 0, 1
           glVertex2f -4, -4
           glVertex2f -10, -10
           glVertex2f -12, -8
           glVertex2f -6, -2
 
    glEnd
    '======================
   
    'lingkaran SOLID badan
    glBegin bmPolygon
    glColor3f 0.74, 0, 1
    For teta = 180 To 360
        x = 4 * Cos(teta * rad2Derajad)
        y = 4 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 4, y - 5
    Next
    glEnd
   
    '=============
    'lingkaran SOLID lonceng
    glBegin bmPolygon
    glColor3f 1, 0.8, 0
    For teta = 1 To 360
        x = 1 * Cos(teta * rad2Derajad)
        y = 1 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 4, y - 6.5
    Next
    glEnd
   
    '=============
    'lingkaran SOLID kalung
    glBegin bmPolygon
    glColor3f 0, 0, 1
    For teta = 1 To 360
        x = 4 * Cos(teta * rad2Derajad)
        y = 4 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 4, y - 2.5
    Next
    glEnd
   
    '=============
        

    'lingkaran SOLID 3 kepala
    glBegin bmPolygon
    glColor3f 1, 0, 0.5
    For teta = 1 To 360
        x = 6 * Cos(teta * rad2Derajad)
        y = 6 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 4, y
    Next
    glEnd
    '=============
    
    'segitiga hidung
    glBegin bmTriangles
    glColor3f 1, 1, 1
    For teta = 1 To 360
              glVertex2f -3, -2
              glVertex2f -4, -3
              glVertex2f -5, -2
    Next
    glEnd
    '=============
   
    'segitiga kuping kiri
    glBegin bmTriangles
    glColor3f 1, 0, 0.5
    glVertex2f -10, 0
    glVertex2f -13, 7
    glVertex2f -7, 5
   
    glEnd
      
    '=============
   
    'segitiga kuping kiri dalam
    glBegin bmTriangles
    glColor3f 0, 0, 0
    glVertex2f -10, 2
    glVertex2f -12, 6
    glVertex2f -8, 4.5
   
    glEnd
    '============
        
    'segitiga kuping kanan
    glBegin bmTriangles
    glColor3f 1, 0, 0.5
    glVertex2f 2, 0
    glVertex2f 5, 7
    glVertex2f -1, 5
   
    glEnd
      
    '=============
   
    'segitiga kuping kanan dalam
    glBegin bmTriangles
    glColor3f 0, 0, 0
    glVertex2f 2, 2
    glVertex2f 4, 6
    glVertex2f 0, 4.5
   
    glEnd
   
     '=============
      'lingkaran SOLID mata kanan
    glBegin bmPolygon
    glColor3f 1, 1, 1
    For teta = 1 To 360
        x = 1.5 * Cos(teta * rad2Derajad)
        y = 1.5 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 7, y
    Next
    glEnd
   
    '=============
       'lingkaran SOLID mata kiri
    glBegin bmPolygon
    glColor3f 1, 1, 1
    For teta = 1 To 360
        x = 1.5 * Cos(teta * rad2Derajad)
        y = 1.5 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 1, y
    Next
    glEnd
    '=============

         'lingkaran SOLID mata kanan dalam
    glBegin bmPolygon
    glColor3f 0, 0, 0
    For teta = 1 To 360
        x = 1 * Cos(teta * rad2Derajad)
        y = 1 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 0.5, y
    Next
    glEnd
   
    '=============
            'lingkaran SOLID mata kiri dalam
    glBegin bmPolygon
    glColor3f 0, 0, 0
    For teta = 1 To 360
        x = 1 * Cos(teta * rad2Derajad)
        y = 1 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 6.5, y
    Next
    glEnd
   
    '===============
        'lingkaran SOLID mulut
    glBegin bmPolygon
    glColor3f 0, 0, 0
    For teta = 180 To 360
        x = 1 * Cos(teta * rad2Derajad)
        y = 1 * Sin(teta * rad2Derajad)
       
        glVertex2f x - 4, y - 4
    Next
    glEnd
   
    '=============
        
       Call Tampilkan
End Sub


 



0 komentar:

Posting Komentar

 

Coretan Rissa Template by Ipietoon Blogger Template | Gift Idea