Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: OpenGL VB.NET
Hello Everyone,
 
What I am trying to do is:
1) Create a polygon, create a texture and apply it to polygon.
 
Next when I want to draw a line, which is a continuous line, I need to re-draw the scene every time.
 
Do I also need to re-draw the polygon??? Because if I dont, it wont appear in the scene and If I do, then the line drawing becomes VERY slow.
 
Attaching the code:
 
Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If e.Button = MouseButtons.Left Then
            painting = True
            If startingPoint.X = 0 And startingPoint.Y = 0 Then
                startingPoint = PointToScreen(e.Location)
            End If
        End If
    End Sub
 
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If (painting) Then
            endPoint = PointToScreen(e.Location)
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT)
            Gl.glMatrixMode(Gl.GL_PROJECTION)
            Gl.glLoadIdentity()
            Gl.glViewport(0, 0, Me.Width, Me.Height)
            Glu.gluOrtho2D(0, Me.Width, Me.Height, 0)
            Gl.glPushMatrix()
            For Each l As line In lineList
                l.drawLine()
            Next
            Gl.glColor3f(0, 100, 0)
            'Use this to give a line width
            'Gl.glLineWidth(10.0F)
            'Use the statement below to enable stipple --
            Gl.glLineStipple(1, &H101)
            Gl.glEnable(Gl.GL_LINE_STIPPLE)
            Gl.glBegin(Gl.GL_LINES)
            Gl.glVertex2f(startingPoint.X, startingPoint.Y)
            Gl.glVertex2f(endPoint.X, endPoint.Y)
            Gl.glEnd()
 
            'Use the statement below to disable the stipple effect for the previously drawn lines
            Gl.glDisable(Gl.GL_LINE_STIPPLE)
            img.imgFile = "D:\\Desert.jpg"
            img.generateTexture()
            Gl.glPopMatrix()
            Gl.glFlush()
            Gdi.SwapBuffers(hDc)
        End If
    End Sub
 
    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        If (painting) Then
            painting = False
            'endPoint = e.Location
            Dim obj As New line
            obj.setStart = startingPoint
            obj.setEnd = endPoint
            lineList.Add(obj)
            startingPoint = endPoint
        End If
 

 

    End Sub
Posted 16-Aug-12 0:17am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

It is required to redraw both texture and line for every frame.
 
Gl.glDisable(Gl.GL_LINE_STIPPLE)
            img.imgFile = "D:\\Desert.jpg"
            img.generateTexture()
 
Is texture loading necessary for each mouse movement ?
 
Normally redrawing a texture and line won't create slow rendering.
 
If any processing which is not related to the mouse movement, and takes much time, then we can use an intermediate texture to hold the output of heavy task. For every frame we can draw that texture with line drawing.
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 693
1 George Jonsson 370
2 BillWoodruff 337
3 Sergey Alexandrovich Kryukov 259
4 Garth J Lancaster 240
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web04 | 2.8.141030.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100