Click here to Skip to main content
15,868,292 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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

1 solution

It is required to redraw both texture and line for every frame.

VB
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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900