我一直負責解決我的知識領域之外的問題,並且我希望能夠從更熟練的openGL人員那裏獲得一些故障排除建議(我非常喜歡對OpenGL有一點經驗)。我們正在研究一個跨平臺的應用程序,這個程序是在一個叫做ccl的通用lisp實現中實現的。在這個應用程序中,我們需要顯示一些顯示文本的3D對象。在Mac上,所有的文本都可以很好地顯示,但是在PC上而不是顯示文本時會顯示其他紋理。起初,我認爲可能是錯誤的紋理被引用,所以我嘗試更改紋理編號,但是列表中的紋理都不是文本(或者紋理被扭曲,看起來不像文本)。我知道這個問題非常模糊,我不是在尋找某人發佈解決方案,但我想知道是否人們可以建議我可能會試着去嘗試解決這個問題的地方。問題解決openGL文本紋理不能正確顯示跨平臺
當我添加打印語句來打印寬像素和像素高的文件時,最終從文件創建紋理的方法(對不起,代碼使用cocoa/cocotron在lisp中編寫) 2的冪(512):
(defun CREATE-IMAGE-FROM-FILE (Filename &key Verbose Forced-Depth (Flip-Vertical t)) "
in: Filename string-or-pathname, &key Verbose boolean, Forced-Depth int,
out: Pixels byte-vector,
Width Height Forced-Depth int; Has-Alpha boolean.
Create an image buffer from <Filename>
- File must be 32 bit ARGB compatible, e.g., .png with mask or 24 bit RGB."
(print "CREATE IMAGE FROM FILE")
(print Filename)
(when Verbose (format t "CREATE-IMAGE-FROM-FILE: ~A~%" Filename))
(let* ((Image-Representation (#/retain (ns-image-rep-from-file (native-string (namestring (translate-logical-pathname Filename)))))))
;; should massage data: GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV for best performance
;; http://developer.apple.com/documentation/graphicsimaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html
(when (%null-ptr-p Image-Representation)
(format t "~%missing texture ~S" Filename)
(return-from create-image-from-file))
;; do the OpenGL vertical image flip
(when Flip-Vertical
(flip-vertical-buffer
(#/bitmapData Image-Representation)
(* (#/bytesPerRow Image-Representation) (#/pixelsHigh Image-Representation))
(#/bytesPerRow Image-Representation)))
(print (#/pixelsWide Image-Representation))
(print (#/pixelsHigh Image-Representation))
(values
(#/bitmapData Image-Representation)
(#/pixelsWide Image-Representation)
(#/pixelsHigh Image-Representation)
(#/bitsPerPixel Image-Representation)
(#/hasAlpha Image-Representation)
(#/bitmapFormat Image-Representation))))
(defmethod DISPLAY-VERTEX-ARRAYS ((Self string-shape))
(glEnable gl_texture_2d)
(cond
;; Color!
((color-vector Self)
(glcolor3ubv (color-vector Self))
(gltexenvi gl_texture_env gl_texture_env_mode gl_blend))
;; Black
(t
(gltexenvi gl_texture_env gl_texture_env_mode gl_modulate)))
(glbindtexture gl_texture_2d (texture (font Self)))
(glInterleavedArrays GL_T2F_V3F (va-stride Self) (vertex-arrays Self))
(glDrawArrays gl_quads 0 (va-elements-count Self))
(gltexenvi gl_texture_env gl_texture_env_mode gl_modulate)
(glDisable gl_texture_2d)
;; if color was use better reset to white?
(when (color-vector Self) (glColor3f 1.0 1.0 1.0)))
alt text http://www.freeimagehosting.net/uploads/e2eaeeca57.png
alt text http://www.freeimagehosting.net/uploads/0a84c32403.png
聽起來像你沒有妥善管理你的記憶。你能提供至少代碼片段或截圖嗎? – 2010-05-26 03:40:26
我添加了一些截圖,第一個截圖是我們在OSX上運行的示例之一(文本顯示正常),第二個示例在Windows 7上運行(看起來,而不是使用正確的紋理文本對象正在使用紋理的盒子)。我會在發佈代碼片段時遇到麻煩,因爲我仍然不確定代碼中發生問題的位置。 – Mike2012 2010-05-26 17:36:24