VB.NET Opengl和纹理 [英] VB.NET Opengl and Textures
问题描述
大家好,
我想做的是:
1)创建一个多边形,创建一个纹理并将其应用于多边形.
接下来,当我要画一条线(是一条连续线)时,我需要每次都重新绘制场景.
我还需要重新绘制多边形吗???因为如果我不这样做,它将不会出现在场景中;如果我这样做了,则线条绘制将变得非常缓慢.
附上代码:
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
推荐答案
需要重新绘制每帧的纹理和线条.
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.
这篇关于VB.NET Opengl和纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!