RaptrFlite
November 2nd, 2005, 03:52 PM
Let me start by saying that I am rendering shaed polygons just fine, it's just when I try to put textures on that I get nothing but a black rectangle.
I wrote the following subroutine to give me a quick and easy way to put a textured rectangle to the screen. It's not very efficient, it doesn't make good use of memory, and it has extra variables from previous versions of the routine, but it's a start. Can someone please tell me what's wrong with it? TIA!
Private Sub DrawTexturedRectangle(V1 As Vector, V2 As Vector, V3 As Vector, V4 As Vector, _
strFile As String, _
Optional VnX As Single, Optional VnY As Single, Optional VnZ As Single)
'Optional returns the Normal to the last vertex
Dim Vn1 As Vector, Vn2 As Vector, Vn3 As Vector, Vn4 As Vector
Dim Vc1 As Vector, Vc2 As Vector, Vc3 As Vector, Vc4 As Vector
Dim Fill_Color(0 To 3) As Single, Line_Color(0 To 3) As Single
Dim sngColor As Single, hTexture As Long, hDC1 As Long, hBitmap
If strFile <> "" And Dir(strFile) <> "" Then
hDC1 = CreateCompatibleDC(0)
hBitmap = LoadBMP(hDC1, strFile)
If hBitmap <> 0 Then
glDisable GL_DEPTH_TEST
glEnable GL_BLEND
glEnable GL_TEXTURE_2D
'Draw and Texture Polygon
glGenTextures 1, hTexture 'Gen Textures
glBindTexture GL_TEXTURE_2D, hTexture
glPixelStorei GL_UNPACK_ALIGNMENT, 1
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
glTexEnvf GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE
glTexImage2D GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, BData(0)
glPushMatrix
glBegin (bmQuads)
Vc1 = VVSubtract(V1, V4): Vc2 = VVSubtract(V3, V4)
Vn1 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn1.X, Vn1.Y, Vn1.Z
glTexCoord2f 0, 0
'glTexCoord3f V4.X, V4.Y, V4.Z
glVertex3f V4.X, V4.Y, V4.Z
Vc1 = VVSubtract(V4, V3): Vc2 = VVSubtract(V2, V3)
Vn2 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn2.X, Vn2.Y, Vn2.Z
glTexCoord2f 1, 0
'glTexCoord3f V3.X, V3.Y, V3.Z
glVertex3f V3.X, V3.Y, V3.Z
Vc1 = VVSubtract(V3, V2): Vc2 = VVSubtract(V1, V2)
Vn3 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn3.X, Vn3.Y, Vn3.Z
glTexCoord2f 1, 1
'glTexCoord3f V2.X, V2.Y, V2.Z
glVertex3f V2.X, V2.Y, V2.Z
Vc1 = VVSubtract(V2, V1): Vc2 = VVSubtract(V4, V1)
Vn4 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn4.X, Vn4.Y, Vn4.Z
glTexCoord2f 0, 1
'glTexCoord3f V1.X, V1.Y, V1.Z
glVertex3f V1.X, V1.Y, V1.Z
glEnd
glPopMatrix
' glEnableClientState GL_COLOR_ARRAY
' glDisable GL_BLEND
glEnable GL_DEPTH_TEST
glDisable GL_TEXTURE_2D
glDeleteTextures 1, hTexture
Call DeleteObject(hBitmap)
End If
Call DeleteDC(hDC1)
Erase BData()
'glDisable (glcTexture2D)
If Not (IsMissing(VnX)) Then
VnX = Vn4.X: VnY = Vn4.Y: VnZ = Vn4.Z
End If
End If
End Sub
I wrote the following subroutine to give me a quick and easy way to put a textured rectangle to the screen. It's not very efficient, it doesn't make good use of memory, and it has extra variables from previous versions of the routine, but it's a start. Can someone please tell me what's wrong with it? TIA!
Private Sub DrawTexturedRectangle(V1 As Vector, V2 As Vector, V3 As Vector, V4 As Vector, _
strFile As String, _
Optional VnX As Single, Optional VnY As Single, Optional VnZ As Single)
'Optional returns the Normal to the last vertex
Dim Vn1 As Vector, Vn2 As Vector, Vn3 As Vector, Vn4 As Vector
Dim Vc1 As Vector, Vc2 As Vector, Vc3 As Vector, Vc4 As Vector
Dim Fill_Color(0 To 3) As Single, Line_Color(0 To 3) As Single
Dim sngColor As Single, hTexture As Long, hDC1 As Long, hBitmap
If strFile <> "" And Dir(strFile) <> "" Then
hDC1 = CreateCompatibleDC(0)
hBitmap = LoadBMP(hDC1, strFile)
If hBitmap <> 0 Then
glDisable GL_DEPTH_TEST
glEnable GL_BLEND
glEnable GL_TEXTURE_2D
'Draw and Texture Polygon
glGenTextures 1, hTexture 'Gen Textures
glBindTexture GL_TEXTURE_2D, hTexture
glPixelStorei GL_UNPACK_ALIGNMENT, 1
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
glTexParameteri GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
glTexEnvf GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE
glTexImage2D GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, BData(0)
glPushMatrix
glBegin (bmQuads)
Vc1 = VVSubtract(V1, V4): Vc2 = VVSubtract(V3, V4)
Vn1 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn1.X, Vn1.Y, Vn1.Z
glTexCoord2f 0, 0
'glTexCoord3f V4.X, V4.Y, V4.Z
glVertex3f V4.X, V4.Y, V4.Z
Vc1 = VVSubtract(V4, V3): Vc2 = VVSubtract(V2, V3)
Vn2 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn2.X, Vn2.Y, Vn2.Z
glTexCoord2f 1, 0
'glTexCoord3f V3.X, V3.Y, V3.Z
glVertex3f V3.X, V3.Y, V3.Z
Vc1 = VVSubtract(V3, V2): Vc2 = VVSubtract(V1, V2)
Vn3 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn3.X, Vn3.Y, Vn3.Z
glTexCoord2f 1, 1
'glTexCoord3f V2.X, V2.Y, V2.Z
glVertex3f V2.X, V2.Y, V2.Z
Vc1 = VVSubtract(V2, V1): Vc2 = VVSubtract(V4, V1)
Vn4 = VectorNormalize(VVCrossProduct(Vc1, Vc2))
glNormal3f Vn4.X, Vn4.Y, Vn4.Z
glTexCoord2f 0, 1
'glTexCoord3f V1.X, V1.Y, V1.Z
glVertex3f V1.X, V1.Y, V1.Z
glEnd
glPopMatrix
' glEnableClientState GL_COLOR_ARRAY
' glDisable GL_BLEND
glEnable GL_DEPTH_TEST
glDisable GL_TEXTURE_2D
glDeleteTextures 1, hTexture
Call DeleteObject(hBitmap)
End If
Call DeleteDC(hDC1)
Erase BData()
'glDisable (glcTexture2D)
If Not (IsMissing(VnX)) Then
VnX = Vn4.X: VnY = Vn4.Y: VnZ = Vn4.Z
End If
End If
End Sub