News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Texture Only Maps To One Face Of Cube

Started by devilhorse, October 30, 2010, 11:20:35 PM

Previous topic - Next topic

devilhorse

Can someone give me a hint on why the code below only produces a texture map on one face of the quad. I have included a screenshot of the outcome from running this code.


xrot            Real4 ?
yrot            Real4 ?
zrot            Real4 ?
texture       DWord ?

rot_speed       Real4 0.5


TranslateFloat Proc x:Real4,y:Real4,z:Real4
Invoke glTranslatef, x,y,z
   Ret
TranslateFloat EndP
RotateFloat Proc angle:Real4,x:Real4,y:Real4,z:Real4
   Invoke glRotatef,angle,x,y,z
   Ret
RotateFloat EndP
TexCoord2f Proc s:Real4,t:Real4
   Invoke glTexCoord2f,s,t
   Ret
TexCoord2f EndP
Vertex3f Proc x:Real4,y:Real4,z:Real4
Invoke glVertex3f,z,y,z
   Ret
Vertex3f EndP
ClearDepth Proc x:Real8
   Invoke glClearDepth,x
   Ret
ClearDepth EndP
Perspective Proc fovy:Real8, aspect:Real8, zNear:Real8, zFar:Real8
Invoke gluPerspective, fovy, aspect, zNear, zFar
   Ret
Perspective EndP
Color3f Proc R:Real4, G:Real4, B:Real4
   Invoke glColor3f, R, G, B
   Ret
Color3f EndP

;==================================================

CreateOpenGLWindow Proc
Local wc:WNDCLASSEX
Local Wwd:DWord
Local Wht:DWord
Local Wtx:DWord
Local Wty:DWord

Mov wc.cbSize, SizeOf WNDCLASSEX
Mov wc.style, 0
Mov wc.lpfnWndProc, Offset OglWndProc
Mov wc.cbClsExtra, NULL
Mov wc.cbWndExtra, NULL
m2m wc.hInstance, App.Instance
Mov wc.hbrBackground, COLOR_WINDOWTEXT + 1
Mov wc.lpszMenuName, NULL
Mov wc.lpszClassName, Offset szOpenGLClassName

Invoke   LoadIcon, App.Instance, 2
Mov wc.hIcon, Eax

Invoke   LoadCursor, NULL, IDC_ARROW
Mov wc.hCursor, Eax
Mov wc.hIconSm, 0

Invoke   RegisterClassEx, Addr wc
Invoke   CreateWindowEx,WS_EX_MDICHILD,
Addr szOpenGLClassName,
CTXT(" "),
MDIS_ALLCHILDSTYLES,
0,
0,
564,
541,
g_hMDIClient,
NULL,
App.Instance,
NULL
Mov hOglWindow, Eax

Invoke   LoadMenu, App.Instance, 600
Invoke   SetMenu, hOglWindow, Eax
Invoke   ShowWindow, hOglWindow, SW_SHOW
Invoke   UpdateWindow, hOglWindow

Call DoTheEvents
      Ret
CreateOpenGLWindow       ENDP
;==========================================================

OglWndProc      Proc   hWin:DWord,uMsg:DWord,wParam:DWord,lParam:DWord
Local WINRect:RECT
Local PixFormat:DWord

Select uMsg, Eax

Case WM_COMMAND
Select wParam, Eax
   Case 1000
      Invoke   SendMessage, hWin, WM_SYSCOMMAND, SC_CLOSE, NULL
   EndSel
      Return 0

Case WM_CREATE
   Invoke   GetDC, hWin
   Mov MainHDC, Eax
   Mov Ax, SizeOf PixFrm
   Mov PixFrm.nSize, Ax
   Mov PixFrm.nVersion, 1
   Mov PixFrm.dwFlags, PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER
   Mov PixFrm.iPixelType, PFD_TYPE_RGBA
   Mov PixFrm.cColorBits, 8
   Mov PixFrm.cDepthBits, 16
   Mov PixFrm.dwLayerMask, PFD_MAIN_PLANE
   ;Mov PixFrm.cAccumBits, 0
   ;Mov PixFrm.cStencilBits, 0
   Invoke   ChoosePixelFormat, MainHDC, Addr PixFrm
   Mov PixFormat, Eax
   Invoke   SetPixelFormat, MainHDC, PixFormat, Addr PixFrm
   Or Eax, Eax
   Jz NoPixelFmt
   Invoke   wglCreateContext, MainHDC
   Mov OpenDC, Eax
   Invoke   wglMakeCurrent, MainHDC, OpenDC
   Invoke   GetClientRect, g_hMDIClient, Addr WINRect
   Invoke   GlInit, WINRect.right, WINRect.bottom

NoPixelFmt:      
   Return 0

Case WM_SIZE

   Invoke   GetClientRect, g_hMDIClient, Addr WINRect

   ;Invoke   ResizeObject, WINRect.right, WINRect.bottom
   Invoke ReSizeGLScene, WINRect.right, WINRect.bottom
   Return 0
            
Case WM_CLOSE

   .If Eax == IDNO
   Return 0
   .EndIf
   Mov Eax, OpenDC
   Or Eax, Eax
   Jz NoGlDC
   ; Delete our objects
   Invoke   DeleteSpheres
   Invoke   wglDeleteContext, OpenDC

NoGlDC:   Invoke   ReleaseDC, hWin, MainHDC
   Invoke   DestroyWindow, hWin
   Return 0

Case WM_DESTROY
Invoke   PostQuitMessage, NULL
   Return 0
EndSel
   Invoke   DefWindowProc, hWin, uMsg, wParam, lParam
   Ret
OglWndProc      ENDP
;===================================================================

DoTheEvents      PROC
         LOCAL   msg:MSG
StartLoop:      ; Check for waiting messages
         invoke   PeekMessage,ADDR msg,0,0,0,PM_NOREMOVE
         or   eax,eax
         jz   NoMsg
         invoke   GetMessage,ADDR msg,NULL,0,0
         or   eax,eax
         jz   ExitLoop
         invoke   TranslateMessage,ADDR msg
         invoke   DispatchMessage,ADDR msg
         jmp   StartLoop
NoMsg:         ; No pending messages: draw the scene
         Invoke   DrawScene
         jmp   StartLoop
ExitLoop:      mov   eax,msg.wParam
         ret
DoTheEvents EndP
;=======================================================

.Const

.Data?
xrot            Real4 ?
yrot            Real4 ?
zrot            Real4 ?
texture       DWord ?

.Data
rot_speed       Real4 0.5
.Code

; --------------- Display the scene
DrawScene      Proc

;allocate a texture name
;Invoke glGenTextures, 1, Addr texture
Invoke glClear, GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT   ;Clear Screen And Depth Buffer
Invoke glLoadIdentity   ;Reset The Current matrix


Invoke TranslateFloat, FP4(0.0), FP4(0.0), FP4(-5.0)      ;Move Into The Screen 5 Units
Invoke RotateFloat, xrot, FP4(1.0), FP4(0.0), FP4(0.0)      ;Rotate On The X Axis
Invoke RotateFloat, yrot, FP4(0.0), FP4(1.0), FP4(0.0)      ;Rotate On The Y Axis
Invoke RotateFloat, zrot, FP4(0.0), FP4(0.0), FP4(1.0)      ;Rotate On The Z Axis

;select our current texture
;Invoke glBindTexture, GL_TEXTURE_2D, 1

; when texture area is small, bilinear filter the closest mipmap
Invoke glTexParameterf,GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST

; when texture area is large, bilinear filter the original
Invoke glTexParameterf, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR

; the texture wraps over at the edges (repeat)
Invoke glTexParameterf, GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT
Invoke glTexParameterf, GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT

Invoke glBegin, GL_QUADS


;================================================
;Front Face
;Bottom Left Of The Texture and Quad
    Invoke TexCoord2f, FP4(0.0), FP4(0.0)
    Invoke Vertex3f, FP4(-1.0), FP4(-1.0), FP4(1.0)

;Bottom Right Of The Texture and Quad
    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f, FP4(1.0), FP4(-1.0), FP4(1.0)

;Top Right Of The Texture and Quad
    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f, FP4(1.0), FP4(1.0), FP4(1.0)

;;Top Left Of The Texture and Quad
    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0), FP4(1.0)
;=================================================

;Back Face
;Bottom Right Of The Texture And Quad
    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f, FP4(-1.0), FP4(-1.0), FP4(-1.0)

;Top Right Of The texture And Quad
    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0), FP4(-1.0)

;Top Left Of The Texture and Quad
    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f, FP4(1.0), FP4(1.0), FP4(-1.0)

;Bottom Left Of The Texture and Quad
    Invoke TexCoord2f, FP4(0.0),FP4(0.0)
    Invoke Vertex3f, FP4(1.0), FP4(-1.0), FP4(-1.0)

;===================================================

;Top Face
    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(0.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f,  FP4(1.0), FP4(1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f,  FP4(1.0), FP4(1.0),FP4(-1.0)
  ;bottom
    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0),FP4(-1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f,  FP4(1.0),FP4(-1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(0.0)
    Invoke Vertex3f,  FP4(1.0),FP4(-1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f, FP4(-1.0),FP4(-1.0), FP4(1.0)
  ;right
    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f,  FP4(1.0),FP4(-1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f,  FP4(1.0), FP4(1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f,  FP4(1.0), FP4(1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(0.0)
    Invoke Vertex3f,  FP4(1.0),FP4(-1.0), FP4(1.0)
  ;left
    Invoke TexCoord2f, FP4(0.0),FP4(0.0)
    Invoke Vertex3f, FP4(-1.0),FP4(-1.0),FP4(-1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(0.0)
    Invoke Vertex3f, FP4(-1.0),FP4(-1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(1.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0), FP4(1.0)

    Invoke TexCoord2f, FP4(0.0),FP4(1.0)
    Invoke Vertex3f, FP4(-1.0), FP4(1.0), FP4(-1.0)

    Invoke glEnd


    Fld xrot
    Fadd rot_speed
    Fstp xrot
    Fld yrot
    Fadd rot_speed
    Fstp yrot
    Fld zrot
   Fadd rot_speed
   Fstp zrot
   invoke   SwapBuffers,MainHDC
         ret
DrawScene      ENDP
;=============================================================

ResizeObject      PROC   ParentW:DWORD,ParentH:DWORD
         invoke   glViewport,0,0,ParentW,ParentH
         invoke   glMatrixMode,GL_PROJECTION
         invoke   glLoadIdentity
         Invoke   Perspective, FP8(45.0), FP8(45.0), FP8(1.0), FP8(1.0)
         invoke   glMatrixMode,GL_MODELVIEW
         invoke   glLoadIdentity
         ret
ResizeObject      ENDP
;=====================================================

LoadGLTexture Proc
  Local hBMP:DWord
  Local ImgInfo:BITMAP
    invoke glGenTextures, 1, ADDR texture
    Invoke LoadImage, App.Instance, IDD_BITMAP, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION
     Mov hBMP, Eax
    Invoke GetObject, hBMP, SizeOf BITMAP, Addr ImgInfo
    Invoke glBindTexture, GL_TEXTURE_2D, 1
    Invoke glTexImage2D, GL_TEXTURE_2D, 0, 3, ImgInfo.bmWidth, ImgInfo.bmHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, ImgInfo.bmBits
    Invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR
    Invoke glTexParameteri, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
      Ret
LoadGLTexture EndP
;========================================================