PDA

View Full Version : textures with taoframework/simpleOpenglControl



appdeveloper
10-09-2009, 01:09 AM
Can anyone give me a simple example of using textures on a Polygon using simpleOpenGlControl and visual basic 2005? I've tried several examples that used other libraries but i wasn't able to make them work.
I'm trying to implement OpenGL on a huge project but Here is the code that i used on a blank project, just to learn how it works, maybe you can find something wrong.


Imports Tao.OpenGl
Imports System.Drawing
Imports System.Drawing.Image
Imports System.Drawing.Imaging

Public Class Form1
Private texture As Integer
Private filter As Single

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.SimpleOpenGlControl1.InitializeContexts()

Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F)
Gl.glMatrixMode(Gl.GL_PROJECTION)
Gl.glLoadIdentity()
Gl.glOrtho(-25.0, 25.0, -25.0, 25.0, -25.0, 25.0)

End Sub


Private Sub renderScene()
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT)
Gl.glPushMatrix()

Const viewAngle As Single = 103.0F
'Gl.glRotatef(viewAngle, 1.0F, 0.2F, 0.0F)

Const axisSize As Single = 25.0F

Gl.glColor3f(1.0F, 0.0F, 0.0F)
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0.0F, 0.0F, -axisSize)
Gl.glVertex3f(0.0F, 0.0F, axisSize)
Gl.glEnd()
' draw a line along the y-axis
Gl.glColor3f(0.0F, 1.0F, 0.0F)
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(0.0F, -axisSize, 0.0F)
Gl.glVertex3f(0.0F, axisSize, 0.0F)
Gl.glEnd()
' draw a line along the x-axis
Gl.glColor3f(0.0F, 0.0F, 1.0F)
Gl.glBegin(Gl.GL_LINES)
Gl.glVertex3f(-axisSize, 0.0F, 0.0F)
Gl.glVertex3f(axisSize, 0.0F, 0.0F)
Gl.glEnd()


Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_NEAREST)
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST)
Gl.glEnable(Gl.GL_TEXTURE_2D)

Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture)
Gl.glBegin(Gl.GL_POLYGON)
'Front(face)

Gl.glNormal3f(0.0, 0.0, 1.0)
Gl.glTexCoord2i(-25, -25) : Gl.glVertex2i(-25, -25)
Gl.glTexCoord2i(-25, 0.0) : Gl.glVertex2i(-25, 25)
Gl.glTexCoord2i(25, 25) : Gl.glVertex2i(25, 25)
Gl.glTexCoord2i(25, -25) : Gl.glVertex2i(25, -25)
Gl.glEnd()



Gl.glPopMatrix()
Gl.glFlush()


End Sub


Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT Or Gl.GL_DEPTH_BUFFER_BIT)
cImg()
renderScene()
End Sub


Private Sub cImg()

texture = New Integer
Gl.glGenTextures(1, texture)
Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture)

Dim mBitmap As Bitmap
mBitmap = New Bitmap("G:\tele.jpg")
Dim m_data As BitmapData = mBitmap.LockBits(New Rectangle(0, 0, mBitmap.Width, mBitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb)


Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_NEAREST)
Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGBA, m_data.Width, m_data.Height, 0, Gl.GL_BGRA, Gl.GL_UNSIGNED_BYTE, m_data.Scan0)

mBitmap.UnlockBits(m_data)



End Sub
End Class

appdeveloper
10-09-2009, 07:14 AM
ok, sorry,... problem already solved on another topic of this forum