Open
Description
;; Main Loop
(loop
with compute = t
while (not (window-should-close))
when compute
do (progn
(pre-compute-mandel-set mandel) ;; renders mandel set into texture using DrawPixel
(setf compute nil))
do (let ((game-time (cl-raylib:get-time)))
(begin-drawing)
(clear-background
*status-panel-background-color*)
(render-visual mandel game-time) ;; see below - simply draws the texture.
(end-drawing)))
;; Pre-compute
(defun pre-compute-mandel-set (state)
(unless (mandel-target-texture state)
(setf (mandel-target-texture state)
(load-render-texture (visual-width state) (visual-height state))))
(format t "computing...")
(begin-texture-mode (mandel-target-texture state)) ;; tests in C show I don't need clear-background here.
(loop
for y below (visual-height state)
do (loop
for x below (visual-width state)
do (draw-pixel
x y (mandel-core
state
y x))))
(draw-line (visual-left state)
(visual-top state)
(+ (visual-left state) (visual-width state))
(+ (visual-top state) (visual-height state))
(make-rgba 255 0 0))
(end-texture-mode)
(format t "...done!~%"))
;; transfer from texture to screen
(defmethod render-visual ((state mandel-state) game-time)
(let ((target-texture (mandel-target-texture state)))
(when target-texture
(draw-texture
(render-texture-texture target-texture)
(visual-left state) (visual-top state) (make-rgba 0 0 0)))))
Neither the set pixels nor the line drawn to the texture ever show on the screen.
To see if it is raylib or the bindings (or me?!), here my C test code:
#include <raylib.h>
#include <stddef.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
static void pre_render_something(RenderTexture2D*texture) {
int x;
int y;
Color color;
BeginTextureMode(*texture);
for (size_t i = 0; i< 1000; i++) {
x = GetRandomValue(0,WINDOW_WIDTH);
y = GetRandomValue(0,WINDOW_HEIGHT);
color.r = GetRandomValue(0,255);
color.g = GetRandomValue(0,255);
color.b = GetRandomValue(0,255);
color.a = 255;
DrawPixel(x,y,color);
DrawPixel(x+1,y,color);
DrawPixel(x,y+1,color);
DrawPixel(x+1,y+1,color);
}
EndTextureMode();
}
int main () {
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Draw Pixels into texture.");
SetRandomSeed(6969);
SetTargetFPS(20);
RenderTexture2D tex = LoadRenderTexture(WINDOW_WIDTH,WINDOW_HEIGHT);
pre_render_something(&tex);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(tex.texture,0,0,RAYWHITE);
EndDrawing();
}
CloseWindow();
return 0;
}
With the C code (which nominally does the very same logical sequence as the lisp code), the pixels show as expected.
Metadata
Assignees
Labels
No labels