Im dabbling around with openGL and textured quads. The problem is that I can't get anything but greyscale. No matter what values I set for the colour channels its always the least significant byte that gets applied to red, green and blue. Anyone know what I'm doing wrong here.
format pe gui 4.0
entry WinMainCRTStartup
include 'win32a.inc'
include 'opengl32.inc'
section '.idata' import data readable writable
library kernel32, 'kernel32.dll',\
user32, 'user32.dll',\
gdi32, 'gdi32.dll',\
opengl32, 'opengl32.dll',\
glu32, 'glu32.dll'
include 'api\kernel32.inc'
include 'api\user32.inc'
include 'api\gdi32.inc'
include 'api\opengl32.inc'
include 'api\glu32.inc'
section '.data' data readable writable
edit db 'edit',0
pfd PIXELFORMATDESCRIPTOR
hDC dd ?
hInstance dd ?
initTime dd ?
thisTime dd ?
scrX dd ?
scrY dd ?
TW = 0x100 ; TextureWidth
TH = 0x100 ; TextureHeight
texX dd ?
texY dd ?
texture db TW*TH*3 dup ?
section '.code' code readable executable
proc WinMainCRTStartup
invoke GetTickCount
mov [initTime], eax
invoke GetSystemMetrics, SM_CXSCREEN
mov [scrX], eax
invoke GetSystemMetrics, SM_CYSCREEN
mov [scrY], eax
stdcall CreateGLWindow, [scrX], [scrY], 0x20
stdcall GenerateTextures, TW, TH, texture
.Main:
invoke GetTickCount
sub eax, [initTime]
mov [thisTime], eax
invoke glClear, GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT
invoke glRotatef, 1.0, 0.0, 0.0, 1.0
invoke glScalef, 1.0, 1.0, 1.0
stdcall TexturedQuad, -0.5, -0.5, 0.0, 1.0, 1.0,\
0.5, -0.5, 0.0, 1.0, 0.0,\
0.5, 0.5, 0.0, 0.0, 0.0,\
-0.5, 0.5, 0.0, 0.0, 1.0
invoke SwapBuffers, [hDC]
invoke GetAsyncKeyState, VK_ESCAPE
or eax, eax
jz .Main
invoke glDeleteTextures, 1, texture
invoke ExitProcess, NULL
endp
proc CreateGLWindow width, height, bpp
mov al, byte [bpp]
mov [pfd.nSize], sizeof.PIXELFORMATDESCRIPTOR
mov [pfd.nVersion], 0x01
mov [pfd.dwFlags], PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov [pfd.iPixelType], PFD_TYPE_RGBA
mov [pfd.cColorBits], al
mov [pfd.cRedBits], 0x00
mov [pfd.cRedShift], 0x00
mov [pfd.cGreenBits], 0x00
mov [pfd.cGreenShift], 0x00
mov [pfd.cBlueBits], 0x00
mov [pfd.cBlueShift], 0x00
mov [pfd.cAlphaBits], 0x00
mov [pfd.cAlphaShift], 0x00
mov [pfd.cAccumBits], 0x00
mov [pfd.cAccumRedBits], 0x00
mov [pfd.cAccumGreenBits], 0x00
mov [pfd.cAccumBlueBits], 0x00
mov [pfd.cAccumAlphaBits], 0x00
mov [pfd.cDepthBits], al
mov [pfd.cStencilBits], 0x00
mov [pfd.cAuxBuffers], 0x00
mov [pfd.iLayerType], 0x00
mov [pfd.bReserved], 0x00
mov [pfd.dwLayerMask], 0x00
mov [pfd.dwVisibleMask], 0x00
mov [pfd.dwDamageMask], 0x00
invoke CreateWindowExA, 0, edit, 0, WS_POPUP or WS_VISIBLE, 0, 0, [width], [height], 0, 0, 0, 0
invoke GetDC, eax
mov [hDC], eax
invoke ChoosePixelFormat, [hDC], pfd
invoke SetPixelFormat, [hDC], eax, pfd
invoke wglCreateContext, [hDC]
invoke wglMakeCurrent, [hDC], eax
invoke ShowCursor, FALSE
ret
endp
proc GenerateTextures width, height, lpPixels
push dword [height]
pop [texY]
push dword [width]
pop [texX]
mov edi, [lpPixels]
mov edx, [height]
dec edx
.loopY:
mov ecx, [width]
dec ecx
.loopX:
mov eax, ecx
or eax, edx
stosb
mov eax, ecx
and eax, edx
stosb
mov eax, ecx
xor eax, edx
stosb
dec ecx
jns .loopX
dec edx
jns .loopY
invoke glEnable, GL_TEXTURE_2D
;invoke glGenTextures, 1, texture
;invoke glBindTexture, GL_TEXTURE_2D, eax
;invoke glTexParameterf, GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR
;invoke glTexParameterf, GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST
invoke gluBuild2DMipmaps, GL_TEXTURE_2D, 1, [texX], [texY], GL_RGB, GL_UNSIGNED_BYTE, texture
ret
endp
proc TexturedQuad x1, y1, z1, u1, v1,\
x2, y2, z2, u2, v2,\
x3, y3, z3, u3, v3,\
x4, y4, z4, u4, v4
invoke glBegin, GL_QUADS
invoke glTexCoord2f, [u1], [v1]
invoke glVertex3f, [x1], [y1], [z1]
invoke glTexCoord2f, [u2], [v2]
invoke glVertex3f, [x2], [y2], [z2]
invoke glTexCoord2f, [u3], [v3]
invoke glVertex3f, [x3], [y3], [z3]
invoke glTexCoord2f, [u4], [v4]
invoke glVertex3f, [x4], [y4], [z4]
invoke glEnd
ret
endp