tex.nim 812 B

1234567891011121314151617181920212223242526272829303132
  1. import
  2. tri_engine/gfx/gl/gl
  3. type
  4. TTex* = object
  5. id*: GLuint
  6. var gWhiteTex = TTex(id: 0)
  7. proc setTexParams() =
  8. ?glTexParameteri(GLtexture2D, GLtextureMinFilter, GLlinear)
  9. #glTexParameteri(GLtexture2D, GLtextureMagFilter, GLlinear)
  10. ?glTexParameteri(GLtexture2D, GLTextureMagFilter, GLnearest)
  11. ?glTexParameteri(GLtexture2D, GLTextureWrapS, GLClampToEdge)
  12. ?glTexParameteri(GLtexture2D, GLTextureWrapT, GLClampToEdge)
  13. proc whiteTex*(): TTex =
  14. if gWhiteTex.id.int != 0:
  15. return gWhiteTex
  16. ?glGenTextures(1, gWhiteTex.id.addr)
  17. ?glBindTexture(GLtexture2D, gWhiteTex.id)
  18. setTexParams()
  19. var pixel = [255'u8, 255'u8, 255'u8, 255'u8]
  20. ?glTexImage2D(GLtexture2D, 0, GLint GL_RGBA, 1, 1, 0, GL_BGRA, cGLUnsignedByte, pixel[0].addr)
  21. ?glBindTexture(GLtexture2D, 0)
  22. result = gWhiteTex