Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

tower defense game in ahk?


  • Please log in to reply
33 replies to this topic
nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

 

 

Wow, sehr beeindruckend!

Für mich leider nicht sehr durchsichtig aufgrund von OpenGL, das ist für mich (noch) ziemlich fremdes Terrain.

Das hat Bentschi für seine OpenGL lib geschrieben.

Ohne Texturen funktioniert das Blending ja aber sobald texturen hinzukommen macht er das nicht mehr.


Visit the new forum ahkscript.org.

http://ahkscript.org


jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
hey nnnik...
kannst du ein komplettes pack zum download zurecht stellen (mit allen includes)
würde es dann später mal testen
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012
Ich hab im Moment keine #Includes aber Hier hab ich das komplette Skript.
Du brauchst noch ein Bild mit dem Namen File.png in deinem Skriptordner
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
	SetBatchLines,-1
	DllCall("LoadLibrary", "str", "opengl32")
    DllCall("LoadLibrary", "str", "glu32")
    DllCall("LoadLibrary", "str", "gdiplus")
	Gui +LastFound
    Gui, % "Color", 0, 0
	hWnd := WinExist()
    hDC := DllCall("GetDC", "ptr", hWnd, "ptr")
	SetFormat,integer,H
	VarSetCapacity(pfd, 40, 0)
	NumPut(40, pfd, 0, "ushort")
    NumPut(1, pfd, 2, "ushort")
    NumPut(0x25, pfd, 4, "uint")
    NumPut(24, pfd, 9, "uchar") 
    NumPut(0, pfd, 18, "uchar") 
    NumPut(16, pfd, 23, "uchar") 
    NumPut(0, pfd, 24, "uchar") 
    if (!(pf := DllCall("ChoosePixelFormat", "ptr", hDC, "ptr", &pfd)))
		ExitApp, -1
	if (!DllCall("SetPixelFormat", "ptr", hDC, "int", pf, "ptr", &pfd))
		ExitApp, -1
	if (!(hRC := DllCall("opengl32\wglCreateContext", "ptr", hDC, "ptr")))
		ExitApp, -1
	DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
    DllCall("opengl32\glEnable", "uint", 0x0B71)
    DllCall("opengl32\glDepthFunc", "uint", 0x0203)
    DllCall("opengl32\glEnable", "uint", 0x0DE1)
	DllCall("opengl32\glEnable", "uint", 0x0BE2)  ;GL_BLEND
	DllCall("opengl32\glBlendFunc","uint",0x0302,"uint",0x0303) 
	DllCall("opengl32\glEnable", "uint", 0x0BC0)
	 Gui, %  "Show", % "w" 800 " h" 600 , test
	 sleep,200
	if (!DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC))
        ExitApp, -1
    DllCall("opengl32\glClear", "uint", 0x00004100)
	DllCall("opengl32\glMatrixMode", "uint", 0x1701)    
	DllCall("opengl32\glLoadIdentity")
	DllCall("opengl32\glOrtho", "double", -4, "double", 4, "double", -3, "double", 3, "double", 0, "double", 4)		
	DllCall("opengl32\glMatrixMode", "uint", 0x1700)     
	DllCall("opengl32\glLoadIdentity")
	v:=aglLoadMipmaps2D(0x0DE1, "File.png")
	llist:=DllCall("opengl32\glGenLists", "int", 1, "uint")
	DllCall("opengl32\glNewList", "uint", llist, "uint", 0x1301)
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glBindTexture", "uint", 0x0DE1, "uint",v)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 3, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 3, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -3, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -3, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glVertex4f", "float", 1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glEndList")
	Loop
	{
	DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
	DllCall("opengl32\glLoadIdentity")
	DllCall("opengl32\glViewport", "int", 0, "int", 0, "int", 800, "int", 600)
	t:=A_Index
	loop,3
	{
	DllCall("opengl32\glPushMatrix")
	DllCall("opengl32\glRotatef", "float", 0, "float", 1.0, "float", 0.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 0.0, "float", 1.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", t*A_Index, "float", 0.0, "float", 0.0, "float", 1.0)
	DllCall("opengl32\glCallList", "uint", llist)
	DllCall("opengl32\glRotatef", "float", -t*A_Index, "float", 0.0, "float", 0.0, "float", 1.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 0.0, "float", 1.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 1.0, "float", 0.0, "float", 0.0)
	DllCall("opengl32\glPopMatrix")
	}
	DllCall("opengl32\glPushMatrix")
	DllCall("opengl32\glColor4f", "float", 1, "float", 1, "float", 1, "float", 5)
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 2, "float", 2, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -2, "float", 2, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -2, "float", -2, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 2, "float", -2, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glPopMatrix")
    DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
    DllCall("SwapBuffers", "ptr", hDC, "ptr", hRC)
    DllCall("opengl32\glClear", "uint", 0x00004300)
    }
	
ExitApp	
	
	
	
	
	__aglChangeTextureColorDepth(byref hBitmap)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"

  size := DllCall("GetObject", ptr, hBitmap, "int", 0, ptr, 0)
  VarSetCapacity(bmi, size, 0)
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")

  hDC := DllCall("GetDC", ptr, 0, ptr)
  hDCsrc := DllCall("CreateCompatibleDC", ptr, hDC, ptr)
  hDCdst := DllCall("CreateCompatibleDC", ptr, hDC, ptr)
  DllCall("ReleaseDC", ptr, hDC)
  DllCall("SelectObject", ptr, hDCsrc, ptr, hBitmap)

  VarSetCapacity(bmi, 40, 0)
  NumPut(40, bmi, 0, "uint")
  NumPut(w, bmi, 4, "int")
  NumPut(h, bmi, 8, "int")
  NumPut(1, bmi, 12, "ushort")
  NumPut(32, bmi, 14, "ushort")

  hBitmapDst := DllCall("CreateDIBSection", ptr, hDCdst, ptr, &bmi, "uint", 0, ptr, 0, ptr, 0, ptr)
  DllCall("SelectObject", ptr, hDCdst, ptr, hBitmapDst)
  DllCall("BitBlt", ptr, hDCdst, "int", 0, "int", 0, "int", w, "int", h, ptr, hDCsrc, "int", 0, "int", 0, "uint", 0x00CC0020)
  DllCall("DeleteDC", ptr, hDCsrc)
  DllCall("DeleteDC", ptr, hDCdst)
  DllCall("DeleteObject", ptr, hBitmap)
  hBitmap := hBitmapDst
  return 1
}

aglGetInteger(pname)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  VarSetCapacity(param, 4, 0)
  DllCall("opengl32\glGetIntegerv", "uint", pname, ptr, &param)
  return NumGet(param, 0, "int")
}

aglIsExt(ext)
{
  astr := (A_IsUnicode) ? "astr" : "str"
  extensions := DllCall("opengl32\glGetString", "uint", 0x1F03, astr)
  if (instr(" " extensions " ", " " ext " "))
    return 1
  return 0
}
	
	
	aglGetVersion()
{
  astr := (A_IsUnicode) ? "astr" : "str"
  if (!version := DllCall("opengl32\glGetString", "uint", 0x1F02, astr))
    return 0
  maj := substr(version, 1, (p := instr(version, "."))-1)
  min := substr(version, p+1)
  if (p := instr(min, "."))
    min := substr(min, 1, p-1)
  if (p := instr(min, " "))
    min := substr(min, 1, p-1)
  if (!min)
    min := 0
  return maj "." min
}
	
	
	
	
	
	
	
	
	
	
	
	
	aglGenTexture()
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  VarSetCapacity(tex, 4, 0)
  DllCall("opengl32\glGenTextures", "int", 1, ptr, &tex)
  return NumGet(tex, 0, "uint")
}
	
__aglTextureBitmap(filename, resize, byref w, byref h, byref format, byref type, byref data)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  sptr := (A_PtrSize) ? A_PtrSize : 4

  if (!fileexist(filename))
    return 0

  if (!(hBitmap := __aglLoadTextureGdip(filename)))
  {
    if (!(hBitmap := __aglLoadTextureGdi(filename)))
      hBitmap := __aglLoadTextureTga(filename)
  }
  if (!hBitmap)
    return 0

  size := DllCall("GetObject", ptr, hBitmap, "int", 0, ptr, 0)
  VarSetCapacity(bmi, size, 0)
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")
  bpp := NumGet(bmi, 14+sptr, "short")

  if (resize)
  {
    __aglCalcTexSize(w, h, neww, newh)
    if ((neww != w) || (newh != h))
    {
      if (!__aglResizeTexture(hBitmap, neww, newh))
      {
        DllCall("DeleteObject", ptr, hBitmap)
        return 0
      }
    }
  }
  bmformat := "BGR"
  if ((aglGetVersion() < 1.2) || (!resize))
  {
    if (__aglRecolorTexture(hBitmap))
      bmformat := "RGB"
  }
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")
  bpp := NumGet(bmi, 14+sptr, "short")
  data := NumGet(bmi, 16+sptr, ptr)
  
  if (bpp=32)
  {
    format := (bmformat="RGB") ? 0x1908 : 0x80E1 ;GL_RGBA : GL_BGRA_EXT
    type := 0x1401 ;GL_UNSIGNED_BYTE
    if (data)
      return 1
  }
  else if (bpp=24)
  {
    format := (bmformat="RGB") ? 0x1907 : 0x80E0 ;GL_RGB : GL_BGR_EXT
    type := 0x1401 ;GL_UNSIGNED_BYTE
    if (data)
      return 1
  }
  
  if (!__aglChangeTextureColorDepth(hBitmap))
  {
    DllCall("DeleteObject", ptr, hBitmap)
    return 0
  }
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")
  bpp := NumGet(bmi, 14+sptr, "short")
  data := NumGet(bmi, 16+sptr, ptr)
  format := (bmformat="RGB") ? 0x1908 : 0x80E1 ;GL_RGBA : GL_BGRA_EXT
  type := 0x1401 ;GL_UNSIGNED_BYTE
  return 1
}	
	
	__aglRecolorTexture(byref hBitmap)
{
  static matrixstr := "0|0|1|0|0|0|1|0|0|0|1|0|0|0|0|0|0|0|1|0|0|0|0|0|1"
  ptr := (A_PtrSize) ? "ptr" : "uint"
  sptr := (A_PtrSize) ? A_PtrSize : 4

  size := DllCall("GetObject", ptr, hBitmap, "int", 0, ptr, 0)
  VarSetCapacity(bmi, size, 0)
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")

  if (!DllCall("GetModuleHandle", "str", "gdiplus", ptr))
  {
    if (!(hGdip := DllCall("LoadLibrary", "str", "gdiplus", ptr)))
      nogdip := 1
  }
  if (!nogdip)
  {
    VarSetCapacity(token, sptr, 0)
    VarSetCapacity(input, 12+sptr, 0)
    NumPut(1, input, 0, "uint")
    DllCall("gdiplus\GdiplusStartup", ptr, &token, ptr, &input, ptr, 0)

    DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", ptr, hBitmap, "int", 0, ptr "*", srcbitmap)
    DllCall("DeleteObject", ptr, hBitmap)
    DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", w, "int", h, "int", 0, "int", 0x26200A, ptr, 0, ptr "*", dstbitmap)
    DllCall("gdiplus\GdipGetImageGraphicsContext", ptr, dstbitmap, ptr "*", dstgraphic)
    DllCall("gdiplus\GdipCreateImageAttributes", ptr "*", attrib)

    VarSetCapacity(matrix, 100, 0)
    Loop, parse, matrixstr, |
      NumPut(A_LoopField, matrix, (A_Index-1)*4, "float")
    DllCall("gdiplus\GdipSetImageAttributesColorMatrix", ptr, attrib, "int", 1, "int", 1, ptr, &matrix, "int", 0, "int", 0)
    DllCall("gdiplus\GdipDrawImageRectRectI", ptr, dstgraphic, ptr, srcbitmap, "int", 0, "int", 0, "int", w, "int", h, "int", 0, "int", 0, "int", w, "int", h, "int", 2, ptr, attrib, ptr, 0, ptr, 0)

    DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", ptr, dstbitmap, ptr "*", hBitmap, "uint", 0xFF000000)
    DllCall("gdiplus\GdipDeleteGraphics", ptr, dstgraphic)
    DllCall("gdiplus\GdipDisposeImage", ptr, srcbitmap)
    DllCall("gdiplus\GdipDisposeImage", ptr, dstbitmap)
    DllCall("gdiplus\GdipDisposeImageAttributes", ptr, attrib)

    DllCall("gdiplus\GdiplusShutdown", ptr, &token)
    if (hGdip)
      DllCall("FreeLibrary", ptr, hGdip)
    return 1
  }
  return 0
}
	
	__aglResizeTexture(byref hBitmap, neww, newh)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  sptr := (A_PtrSize) ? A_PtrSize : 4

  size := DllCall("GetObject", ptr, hBitmap, "int", 0, ptr, 0)
  VarSetCapacity(bmi, size, 0)
  DllCall("GetObject", ptr, hBitmap, "int", size, ptr, &bmi)
  w := NumGet(bmi, 4, "int")
  h := NumGet(bmi, 8, "int")

  if (!DllCall("GetModuleHandle", "str", "gdiplus", ptr))
  {
    if (!(hGdip := DllCall("LoadLibrary", "str", "gdiplus", ptr)))
      nogdip := 1
  }
  if (!nogdip)
  {
    VarSetCapacity(token, sptr, 0)
    VarSetCapacity(input, 12+sptr, 0)
    NumPut(1, input, 0, "uint")
    DllCall("gdiplus\GdiplusStartup", ptr, &token, ptr, &input, ptr, 0)

    DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", ptr, hBitmap, "int", 0, ptr "*", srcbitmap)
    DllCall("DeleteObject", ptr, hBitmap)
    DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", neww, "int", newh, "int", 0, "int", 0x26200A, ptr, 0, ptr "*", dstbitmap)
    DllCall("gdiplus\GdipGetImageGraphicsContext", ptr, dstbitmap, ptr "*", dstgraphic)
    DllCall("gdiplus\GdipCreateImageAttributes", ptr "*", attrib)

    DllCall("gdiplus\GdipSetImageAttributesColorMatrix", ptr, attrib, "int", 1, "int", 1, ptr, 0, "int", 0, "int", 0)
    DllCall("gdiplus\GdipSetInterpolationMode", ptr, dstgraphic, "int", 3)
    DllCall("gdiplus\GdipDrawImageRectRectI", ptr, dstgraphic, ptr, srcbitmap, "int", 0, "int", 0, "int", neww, "int", newh, "int", 0, "int", 0, "int", w, "int", h, "int", 2, ptr, attrib, ptr, 0, ptr, 0)

    DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", ptr, dstbitmap, ptr "*", hBitmap, "uint", 0xFF000000)
    DllCall("gdiplus\GdipDeleteGraphics", ptr, dstgraphic)
    DllCall("gdiplus\GdipDisposeImage", ptr, srcbitmap)
    DllCall("gdiplus\GdipDisposeImage", ptr, dstbitmap)
    DllCall("gdiplus\GdipDisposeImageAttributes", ptr, attrib)

    DllCall("gdiplus\GdiplusShutdown", ptr, &token)
    if (hGdip)
      DllCall("FreeLibrary", ptr, hGdip)
    return 1
  }

  hDC := DllCall("GetDC", ptr, 0, ptr)
  hDCsrc := DllCall("CreateCompatibleDC", ptr, hDC, ptr)
  hDCdst := DllCall("CreateCompatibleDC", ptr, hDC, ptr)
  DllCall("ReleaseDC", ptr, hDC)
  DllCall("SelectObject", ptr, hDCsrc, ptr, hBitmap)

  VarSetCapacity(bmi, 40, 0)
  NumPut(40, bmi, 0, "uint")
  NumPut(neww, bmi, 4, "int")
  NumPut(newh, bmi, 8, "int")
  NumPut(1, bmi, 12, "ushort")
  NumPut(32, bmi, 14, "ushort")

  hBitmapDst := DllCall("CreateDIBSection", ptr, hDCdst, ptr, &bmi, "uint", 0, ptr, 0, ptr, 0, ptr)
  DllCall("SelectObject", ptr, hDCdst, ptr, hBitmapDst)
  DllCall("SetStretchBltMode", ptr, hDCdst, "int", 4)
  DllCall("SetBrushOrgEx", ptr, hDCdst, "int", 2, "int", 2, ptr, 0)
  DllCall("StretchBlt", ptr, hDCdst, "int", 0, "int", 0, "int", neww, "int", newh, ptr, hDCsrc, "int", 0, "int", 0, "int", w, "int", h, "uint", 0x00CC0020)
  DllCall("DeleteDC", ptr, hDCsrc)
  DllCall("DeleteDC", ptr, hDCdst)
  DllCall("DeleteObject", ptr, hBitmap)
  hBitmap := hBitmapDst
  return 1
}
	
	__aglCalcTexSize(w, h, byref neww, byref newh)
{
  maxsize := aglGetInteger(0x0D33) ;GL_MAX_TEXTURE_SIZE
  if ((w > maxsize) || (h > maxsize) || ((aglGetVersion() < 2.1) && (!aglIsExt("GL_ARB_texture_non_power_of_two"))))
  {
    sizes := 0
    Loop
    {
      if ((2**(A_Index-1)) > maxsize)
        break
      sizes ++
    }
    Loop, % sizes-1
    {
      if ((2**(A_Index-1))>=w)
        break
      neww := (2**A_Index)
    }
    Loop, % sizes-1
    {
      if ((2**(A_Index-1))>=h)
        break
      newh := (2**A_Index)
    }
    return 1
  }
  neww := w
  newh := h
  return 1
}
	
__aglLoadTextureGdi(filename)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  if (hBitmap := DllCall("LoadImage", ptr, 0, "str", filename, "uint", 0, "int", 0, "int", 0, "uint", 0x10))
    return hBitmap
  return 0
}

__aglLoadTextureTga(filename)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  if (!(hFile := DllCall("CreateFile", "str", filename, "uint", 0x80000000, "uint", 1, ptr, 0, "uint", 3, "uint", 0, ptr, 0, ptr)))
    return 0
  size := DllCall("GetFileSize", ptr, hFile, ptr, 0, "uint")
  if (size > 4096*4096*4 + 300)
    return 0

  VarSetCapacity(file, size, 0)
  if ((!DllCall("ReadFile", ptr, hFile, ptr, &file, "uint", size, "uint*", read, ptr, 0)) || (read < size))
  {
    DllCall("CloseHandle", ptr, hFile)
    return 0
  }
  DllCall("CloseHandle", ptr, hFile)

  identicationlength := NumGet(file, 0, "uchar")
  colormaptype := NumGet(file, 1, "uchar")
  imagetype := NumGet(file, 2, "uchar")
  colormaporign := NumGet(file, 3, "ushort")
  colormaplength := NumGet(file, 5, "ushort")
  colormapentrysize := NumGet(file, 7, "uchar")
  xorign := NumGet(file, 8, "ushort")
  yorign := NumGet(file, 10, "ushort")
  w := NumGet(file, 12, "ushort")
  h := NumGet(file, 14, "ushort")
  bitcount := NumGet(file, 16, "uchar")
  imagedescriptor := NumGet(file, 17, "uchar")
  numattrib := imagedescriptor & 0xF
  screenorign := imagedescriptor & 0x20
  interleaving := (imagedescriptor & 0xC0) >> 6

  identication := &file + 18
  colormap := identication + identicationlength
  imagedata := colormap + (colormaplength * colormapentrysize)
  imagedatalength := size - (18 + identicationlength + (colormaplength * colormapentrysize))

  if imagetype not in 1,2,3,9,10,11,32,33 ;all types
    return 0

  ;0  -  No image data included.
  ;1  -  Uncompressed, color-mapped images.
  ;2  -  Uncompressed, RGB images.
  ;3  -  Uncompressed, black and white images.
  ;9  -  Runlength encoded color-mapped images.
  ;10  -  Runlength encoded RGB images.
  ;11  -  Compressed, black and white images.
  ;32  -  Compressed color-mapped data, using Huffman, Delta, and runlength encoding.
  ;33  -  Compressed color-mapped data, using Huffman, Delta, and runlength encoding.  4-pass quadtree-type process.

  if imagetype not in 2,3 ;currently supportet types
    return 0

  VarSetCapacity(bmi, 40, 0)
  NumPut(40, bmi, 0, "int")
  NumPut(w, bmi, 4, "int")
  NumPut((screenorign) ? -h : h, bmi, 8, "int")
  NumPut(1, bmi, 12, "ushort")
  if imagetype in 1,9,32
    NumPut(bpp := colormapentrysize, bmi, 14, "ushort")
  else
    NumPut(bpp := bitcount, bmi, 14, "ushort")
  if imagetype in 9,10
    NumPut(2, bmi, 16, "uint")

  datasize := w*h*Round(bpp/8)
  if (imagedatalength > datasize)
    imagedatalength := datasize

  hDC := DllCall("GetDC", ptr, 0, ptr)
  hDCbm := DllCall("CreateCompatibleDC", ptr, hDC, ptr)
  DllCall("ReleaseDC", ptr, hDC)
  if (hBitmap := DllCall("CreateDIBSection", ptr, hDCbm, ptr, &bmi, "uint", 0, ptr "*", bits, ptr, 0, ptr))
      DllCall("RtlMoveMemory", ptr, bits, ptr, imagedata, "uint", imagedatalength)
  DllCall("DeleteDC", ptr, hDCbm)
  return hBitmap
}	



__aglLoadTextureGdip(filename)
{
  ptr := (A_PtrSize) ? "ptr" : "uint"
  sptr := (A_PtrSize) ? A_PtrSize : 4
  astr := (A_IsUnicode) ? "astr" : "str"

  if (!DllCall("GetModuleHandle", "str", "gdiplus", ptr))
  {
    if (!(hGdip := DllCall("LoadLibrary", "str", "gdiplus", ptr)))
      return 0
  }
  VarSetCapacity(token, sptr, 0)
  VarSetCapacity(input, 12+sptr, 0)
  NumPut(1, input, 0, "uint")
  DllCall("gdiplus\GdiplusStartup", ptr, &token, ptr, &input, ptr, 0)

  VarSetCapacity(wfilename, wfilenamesize := (strlen(filename)*2+2), 0)
  DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, astr, filename, "int", -1, ptr, &wfilename, "int", wfilenamesize)

  DllCall("gdiplus\GdipCreateBitmapFromFile", ptr, &wfilename, ptr "*", bitmap)
  DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", ptr, bitmap, ptr "*", hBitmap, "uint", 0xFF000000)
  DllCall("gdiplus\GdipDisposeImage", ptr, bitmap)

  DllCall("gdiplus\GdiplusShutdown", ptr, &token)
  if (hGdip)
    DllCall("FreeLibrary", ptr, hGdip)
  return hBitmap
}


aglLoadMipmaps2D(target, filename, components=4, minfilter=0x2601, magfilter=0x2601, loadonce=0)
{
  static
  if (loadonce)
  {
    loop, % loaded
    {
      if (tex_%A_Index% = filename)
        return texnum_%A_Index%
    }
  }
  ptr := (A_PtrSize) ? "ptr" : "uint"
  if (!(__aglTextureBitmap(filename, 0, w, h, format, type, data)))
    return 0
  tex := aglGenTexture()
  DllCall("opengl32\glBindTexture", "uint", target, "uint", tex)
  DllCall("opengl32\glTexParameteri", "uint", target, "uint", 0x2800, "uint", magfilter)
  DllCall("opengl32\glTexParameteri", "uint", target, "uint", 0x2801, "uint", minfilter)
  DllCall("glu32\gluBuild2DMipmaps", "uint", target, "uint", components, "int", w, "int", h, "int", format, "uint", type, ptr, data)
  DllCall("DeleteObject", ptr, hBitmap)
  loaded := (!loaded) ? 1 : loaded+1
  tex_%loaded% := filename
  texnum_%loaded% := tex
  return tex
}

Visit the new forum ahkscript.org.

http://ahkscript.org


nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Ich hab jetzt das Problem gelöst und damit einen sehr grossen Schritt nach vorne gemacht.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

	SetBatchLines,-1
	DllCall("LoadLibrary", "str", "opengl32")
    DllCall("LoadLibrary", "str", "glu32")
    DllCall("LoadLibrary", "str", "gdiplus")
	Gui +LastFound
    Gui, % "Color", 0, 0
	hWnd := WinExist()
    hDC := DllCall("GetDC", "ptr", hWnd, "ptr")
	SetFormat,integer,H
	VarSetCapacity(pfd, 40, 0)
	NumPut(40, pfd, 0, "ushort")
    NumPut(1, pfd, 2, "ushort")
    NumPut(0x25, pfd, 4, "uint")
    NumPut(24, pfd, 9, "uchar") 
    NumPut(0, pfd, 18, "uchar") 
    NumPut(16, pfd, 23, "uchar") 
    NumPut(0, pfd, 24, "uchar") 
    if (!(pf := DllCall("ChoosePixelFormat", "ptr", hDC, "ptr", &pfd)))
		ExitApp, -1
	if (!DllCall("SetPixelFormat", "ptr", hDC, "int", pf, "ptr", &pfd))
		ExitApp, -1
	if (!(hRC := DllCall("opengl32\wglCreateContext", "ptr", hDC, "ptr")))
		ExitApp, -1
	DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
    DllCall("opengl32\glEnable", "uint", 0x0B71)
    DllCall("opengl32\glDepthFunc", "uint", 0x0203)
    DllCall("opengl32\glEnable", "uint", 0x0DE1)
	DllCall("opengl32\glEnable", "uint", 0x0BE2)  ;GL_BLEND
	DllCall("opengl32\glBlendFunc","uint",0x0302,"uint",0x0303) 
	DllCall("opengl32\glEnable", "uint", 0x0BC0)
	 Gui, %  "Show", % "w" 800 " h" 600 , test
	 sleep,200
	if (!DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC))
        ExitApp, -1
    DllCall("opengl32\glClear", "uint", 0x00004100)
	DllCall("opengl32\glMatrixMode", "uint", 0x1701)    
	DllCall("opengl32\glLoadIdentity")
	DllCall("opengl32\glOrtho", "double", -4, "double", 4, "double", -3, "double", 3, "double", 0, "double", 4)		
	DllCall("opengl32\glMatrixMode", "uint", 0x1700)     
	DllCall("opengl32\glLoadIdentity")
	v:=aglLoadMipmaps2D("File.png")
	v2:=aglLoadMipmaps2D("FileB.png")
	llist:=DllCall("opengl32\glGenLists", "int", 1, "uint")
	DllCall("opengl32\glColor4f", "float", 1, "float", 1, "float", 1, "float", 1)
	DllCall("opengl32\glNewList", "uint", llist, "uint", 0x1301)
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glBindTexture", "uint", 0x0DE1, "uint",v)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 3, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 3, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -1, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -3, "float", 1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -3, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -1, "float", -1, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glEndList")
	Loop
	{
	DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
	DllCall("opengl32\glLoadIdentity")
	DllCall("opengl32\glViewport", "int", 0, "int", 0, "int", 800, "int", 600)
	t:=A_Index
	DllCall("opengl32\glBindTexture", "uint", 0x0DE1, "uint",v2)
	DllCall("opengl32\glBegin", "uint", 7)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 1)
	DllCall("opengl32\glVertex4f", "float", 4, "float", 3, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 1)
	DllCall("opengl32\glVertex4f", "float", -4, "float", 3, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 1, "float", 0)
	DllCall("opengl32\glVertex4f", "float", -4, "float", -3, "float", 0, "float", 1)
	DllCall("opengl32\glTexCoord2f", "float", 0, "float", 0)
	DllCall("opengl32\glVertex4f", "float", 4, "float", -3, "float", 0, "float", 1)
	DllCall("opengl32\glEnd")
	DllCall("opengl32\glBindTexture", "uint", 0x0DE1, "uint",v)
	loop,20
	{
	DllCall("opengl32\glPushMatrix")
	DllCall("opengl32\glRotatef", "float", 0, "float", 1.0, "float", 0.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 0.0, "float", 1.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", t*A_Index, "float", 0.0, "float", 0.0, "float", 1.0)
	DllCall("opengl32\glCallList", "uint", llist)
	DllCall("opengl32\glRotatef", "float", -t*A_Index+A_Index*30, "float", 0.0, "float", 0.0, "float", 1.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 0.0, "float", 1.0, "float", 0.0)
	DllCall("opengl32\glRotatef", "float", 0, "float", 1.0, "float", 0.0, "float", 0.0)
	DllCall("opengl32\glPopMatrix")
	}
    DllCall("opengl32\wglMakeCurrent", "ptr", hDC, "ptr", hRC)
    DllCall("SwapBuffers", "ptr", hDC, "ptr", hRC)
    DllCall("opengl32\glClear", "uint", 0x00004300)
    }
	
ExitApp	


aglLoadMipMaps2D(filename)
  {
    VarSetCapacity(in, 20, 0)
    NumPut(1, in, 0, "int")
    if (DllCall("gdiplus\GdiplusStartup", "ptr*", token, "ptr", &in, "ptr", 0)!=0)
      return 0 
    if (DllCall("gdiplus\GdipCreateBitmapFromFile", "wstr", filename, "ptr*", pBitmap))
      return 0 
    r := 0
    if (DllCall("gdiplus\GdipGetImageWidth", "ptr", pBitmap, "uint*", w)=0 && DllCall("gdiplus\GdipGetImageHeight", "ptr", pBitmap, "uint*", h)=0)
    {
      VarSetCapacity(rc, 16, 0)
      NumPut(w, rc, 8, "int")
      NumPut(h, rc, 12, "int")
      VarSetCapacity(bgpbmdata, 32, 0)
      if (DllCall("gdiplus\GdipBitmapLockBits", "ptr", pBitmap, "ptr", &rc, "uint", 0x0001, "int", 0x26200A, "ptr", &bgpbmdata)=0)
      {
        scan := NumGet(bgpbmdata, 16, "ptr")
        DllCall("opengl32\glGenTextures", "uint", 1, "uint*", tex)
		DllCall("opengl32\glBindTexture", "uint", 0x0DE1, "uint", tex)
		if (w>0 && h>0)
			DllCall("opengl32\glTexImage2D", "int", 0x0DE1, "int", 0, "int", 0x1908, "int", w, "int", h, "int", 0, "int", 	0x80E1, "int", 0x1401, "ptr", scan)
		    DllCall("opengl32\glTexParameteri", "int", 0x0DE1, "int", 0x2801, "int", 0x2601)
			DllCall("opengl32\glTexParameteri", "int", 0x0DE1, "int", 0x2800, "int", 0x2601)
        DllCall("gdiplus\GdipBitmapUnlockBits", "ptr", pBitmap, "ptr", &bgpbmdata)
      }
    }
    DllCall("gdiplus\GdipDisposeImage", "ptr", pBitmap)
    DllCall("gdiplus\GdiplusShutdown", "ptr", token)
    return tex
  }
  

Visit the new forum ahkscript.org.

http://ahkscript.org


nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Jeder der sich über OpenGL informieren will findet hier Informationen zu dem Thema:

http://wiki.delphigl....php/Hauptseite


Visit the new forum ahkscript.org.

http://ahkscript.org


nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Ich sitz immer noch dran nehm mir aber erstmal eine Pause.

Wenn ich noch einen 4th level Pointer in C++ sehe bekomm ich Anfälle.


Visit the new forum ahkscript.org.

http://ahkscript.org


fump2000
  • Members
  • 591 posts
  • Last active: Nov 11 2015 07:52 AM
  • Joined: 01 Nov 2012

Auf jeden Fall zolle ich dir Respekt für deine Arbeit. Hängst dich immer sehr rein und machst sehr viel! Danke dafür!



nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

OK ich werde mal meine Planungen ausführlich darstellen:
 
1.Es gibt eine Game Class.
Diese enthält alle Eigenschaften des Spiels, z.B. ob man Scrollen kann, welche Gui genutzt wird etc...:

Game.init("opengl") ; oder GDI+
Game.Gui:=hwnd
Game.size(800,600) ; grösse des Spiels als die Bilder erstellt wurden (nicht die Grösse des momentanen Fensters)
Game.Scrollable:=1

Diese Game Class hat eine Unterclass namens World in der sich alle zeichenbaren Objekte befinden.
 

Game.World.size:=(-4.0,-3.0,4.0,3.0) 

Bei der World Class wird mit relativen Koordinaten gerechnet Der Bildschirm ist 8.0 Einheiten Breit und beginnt bei -4 er ist ausserdem 6 Einheiten hoch und beginnt bei -3
Wenn man ein Spiel machen möchte, welches Scrollbar ist sollte man also grössere Werte nehmen z.B.:

Game.World.Size:=(-10,-10,10,10)

Die oberen Werte sind schon Standardmäßig eingestellt.
 
In der World Class hat man die Möglichkeit Klassen zu registrieren die im Spiel Vorkommen sollen:

Game.World.enemy.register(new enemy())

Class Enemy
{
HP:="UInt:100"
Distance:="UInt:0"
OnTic:="OnEnemyTic"
OnDraw:="OnEnemyDraw"

Class EnemyLocation
{
size:="float:0.5"
x:="Float"
y:="Float"
rot:="UINT"
List:="Enemy.png"
}

__new(){
Location:= new this.EnemyLocation()
}
}
OnEnemyTic(){
Msgbox % "Tic"
}
OnEnemyDraw(){

Msgbox % Draw
}

Dabei gibt es aber Besonderheiten:
Es muss eine Unterklasse Location geben:
Diese enthält die Positions und Zeichen-Daten des Objekts nämlich die größe, (nicht die Wirkliche größe sondern die größe die bestimmt ob ein Objekt innerhalb des sichtbaren Bereiches ist oder nicht.)die x position, die y position, die Rotation und das Bild(benannt List).
Es ist wichtig, dass ihr diese Namen in der Location Class beibehaltet, die Location Class darf auch nichts anderes beinhalten.
In der Location Class kann es auch mehrere Bilder geben jeweils dann benannt x2,y2,rot2,List2, aber kein size2 man kann auch x3 etc. verwenden.
Wenn ihr Werte Registriert muss hinter dem Wert, es sei denn es sind besondere Werte wie z.B. List oder OnTic oder OnDraw, der Datentyp stehen : z.B. HP:="UInt"
Wenn man zusätzlich noch einen standard Wert festlegen will, kann man diesen nach einem Doppelpunkt hinschreiben.
Ich bitte euch nicht den Datentyp String zu benutzen da ihr mir damit unmengen an Arbeit machen würdet.
 
Zudem gibt es noch die OnTic und OnDraw Funktionen:
Die OnTic Funktion wird jedesmal wenn neu gezeichnet wird, aufgerufen, unabhängig ob das Objekt nun gezeichnet wird oder nicht.
Die OnDraw Funktion wird nur aufgerufen, wenn das objekt gezeichnet wird (es wird z.B. nicht gezeichnet wenn x und y + size ausserhalb der Cam sind)

In der OnTic Funktion solltet ihr x,y sowie alles berechnen, was euer Objekt auch tut selbst wenn es nicht dargestellt wird (z.B. Tower schießen...).

 

In der OnDraw Funktion solltet ihr x2-x.. sowie y2-y.. und rot-rot... und alles berechnen, was euer Objekt nur tut, wenn es neu gezeichnet wird. 

z.B. Muss man Schaden nicht unbedingt anzeigen wenn ein Objekt nicht sichtbar ist.

 

Es ist wichtig, dass man die Funktions Namen und nicht ein func-Objekt übergibt.

(Es muss ein register-Callback erstellt werden.)

 

 

In der World class erstellt man nun ein neues Objekt mit der Funktion:

newenemyid:=Game.World.enemy.add("x:0,y:0")

Der Rückgabewert ist eine ID mit der man das neue Objekt genauer Identifizieren kann.

Man muss um auf das Objekt zugreifen zu können sich also das Id Objekt merken.

Da direkt mit dem Zeichnen angefangen wird sollte man x und y Werte übergeben.

Man kann nun mit der ID auf das Objekt zugreifen:

Msgbox % Game.World.Enemy[EnemyId].HP

Sorry ab hier hab ich keine Zeit mehr :'(


Visit the new forum ahkscript.org.

http://ahkscript.org


fump2000
  • Members
  • 591 posts
  • Last active: Nov 11 2015 07:52 AM
  • Joined: 01 Nov 2012

Wirklich ein riesen Projekt. Hoffe du bekommst es fertig :) Bin sehr gespannt!



D_FoX
  • Members
  • 77 posts
  • Last active: Oct 17 2013 11:26 PM
  • Joined: 08 May 2013

Urkrass :D



nepter
  • Members
  • 53 posts
  • Last active: Jun 05 2019 07:59 AM
  • Joined: 29 Jun 2012

What about using Direct2d instead of gdi+ , more simple.



nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

OpenGL works fine for me ;)


Visit the new forum ahkscript.org.

http://ahkscript.org


nnnik
  • Members
  • 1625 posts
  • Last active: Jan 24 2019 02:19 PM
  • Joined: 28 Jul 2012

Nun nachdem ich nun eine Pause genommen habe arbeite ich mal weiter.
Ich denke ihr könnt bald den ersten Code auf Github sehen.


Visit the new forum ahkscript.org.

http://ahkscript.org


Alibaba
  • Members
  • 435 posts
  • Last active: Nov 19 2014 04:21 PM
  • Joined: 01 Nov 2012

+1


Find the recent autohotkey version here: ahkscript.org


unknow_user
  • Members
  • 64 posts
  • Last active: Sep 22 2014 07:33 PM
  • Joined: 08 Apr 2013

habe dieses tehma ursprünglich aus neugier angefangen aber fehler gemacht...

kann jemand die diskusion mal nach spiele verschieben?