01-23-2026, 03:18 AM
ME! ID SAY DONT USE IT! No normals, no lighting, etc...and unless Qwerky makes his stuff into a lib for shapes and mapping textures to em and then adds scaling etc...its a mine field...
Learn GL (Qb64 does nartive supprt for v 1.1) @MasterGY will be happy to help ya there and so will I. I now am all about doing it in C++ and passing commands to QB64...and for me...its been one hell of a hill to climb so i wouldnt recommend it lightly!
For fast images ask @Pete for hardware advice...failing that....Googles ai will in a few mins teach you what you want to know...like i know how to use it but two questions and i got this....
Then one more question got me this :
If you ask it to add comments step by step it will, and also it make you anything you want!
john
Learn GL (Qb64 does nartive supprt for v 1.1) @MasterGY will be happy to help ya there and so will I. I now am all about doing it in C++ and passing commands to QB64...and for me...its been one hell of a hill to climb so i wouldnt recommend it lightly!
For fast images ask @Pete for hardware advice...failing that....Googles ai will in a few mins teach you what you want to know...like i know how to use it but two questions and i got this....
Code: (Select All)
' Solid Rotating 3D Cube with Multi-Color Faces
SCREEN _NEWIMAGE(800, 600, 32)
' 1. Create a Hardware Texture Atlas
temp& = _NEWIMAGE(1536, 256, 32) ' 6 faces * 256 pixels
_DEST temp&
FOR i = 0 TO 5
LINE (i * 256, 0)-((i + 1) * 256 - 1, 255), _RGB32(i * 40, 200 - i * 30, 255 - i * 20), BF
NEXT i
_DEST 0
tex& = _COPYIMAGE(temp&, 33): _FREEIMAGE temp&
' Define the 8 static corners of a cube (local coordinates)
TYPE Point3D
x AS SINGLE: y AS SINGLE: z AS SINGLE
END TYPE
DIM v(1 TO 8) AS Point3D ' Vertices
v(1).x = -1: v(1).y = 1: v(1).z = 1 ' Front-Top-Left
v(2).x = 1: v(2).y = 1: v(2).z = 1 ' Front-Top-Right
v(3).x = 1: v(3).y = -1: v(3).z = 1 ' Front-Bot-Right
v(4).x = -1: v(4).y = -1: v(4).z = 1 ' Front-Bot-Left
v(5).x = -1: v(5).y = 1: v(5).z = -1 ' Back-Top-Left
v(6).x = 1: v(6).y = 1: v(6).z = -1 ' Back-Top-Right
v(7).x = 1: v(7).y = -1: v(7).z = -1 ' Back-Bot-Right
v(8).x = -1: v(8).y = -1: v(8).z = -1 ' Back-Bot-Left
DIM rv(1 TO 8) AS Point3D ' Rotated Vertices
DO
_LIMIT 60: CLS
a! = TIMER * 0.5: zo = -5 ' Angle and Depth
' 2. Rotate all vertices first as a single solid unit
FOR i = 1 TO 8
x = v(i).x: y = v(i).y: z = v(i).z
' Rotate Y
nx = x * COS(a!) - z * SIN(a!): nz = x * SIN(a!) + z * COS(a!)
x = nx: z = nz
' Rotate X
ny = y * COS(a! * 0.7) - z * SIN(a! * 0.7): nz = y * SIN(a! * 0.7) + z * COS(a! * 0.7)
' Store final position with depth offset
rv(i).x = x: rv(i).y = ny: rv(i).z = nz + zo
NEXT i
' 3. Draw faces using the pre-rotated vertices
' Front face (v1, v2, v3, v4)
DrawFace rv(1), rv(2), rv(3), rv(4), tex&, 0
' Back face (v6, v5, v8, v7)
DrawFace rv(6), rv(5), rv(8), rv(7), tex&, 256
' Left face (v5, v1, v4, v8)
DrawFace rv(5), rv(1), rv(4), rv(8), tex&, 512
' Right face (v2, v6, v7, v3)
DrawFace rv(2), rv(6), rv(7), rv(3), tex&, 768
' Top face (v5, v6, v2, v1)
DrawFace rv(5), rv(6), rv(2), rv(1), tex&, 1024
' Bottom face (v4, v3, v7, v8)
DrawFace rv(4), rv(3), rv(7), rv(8), tex&, 1280
_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)
SUB DrawFace (p1 AS Point3D, p2 AS Point3D, p3 AS Point3D, p4 AS Point3D, img&, tx)
' Each face is 2 triangles.
_MAPTRIANGLE (tx, 0)-(tx + 255, 0)-(tx + 255, 255), img& TO(p1.x, p1.y, p1.z)-(p2.x, p2.y, p2.z)-(p3.x, p3.y, p3.z)
_MAPTRIANGLE (tx, 0)-(tx + 255, 255)-(tx, 255), img& TO(p1.x, p1.y, p1.z)-(p3.x, p3.y, p3.z)-(p4.x, p4.y, p4.z)
END SUB
Then one more question got me this :
Code: (Select All)
' QB64-PE: 3D Bouncing Spheres and Cubes (No Culling)
SCREEN _NEWIMAGE(1000, 700, 32)
RANDOMIZE TIMER
' 1. Create a Hardware Texture for our objects
t& = _NEWIMAGE(256, 256, 32): _DEST t&
FOR i = 0 TO 255: LINE (i, 0)-(i, 255), _RGB32(i, 100, 255 - i): NEXT i
_DEST 0: tex& = _COPYIMAGE(t&, 33): _FREEIMAGE t&
' Object Definitions
TYPE Point3D: x AS SINGLE: y AS SINGLE: z AS SINGLE: END TYPE
TYPE Entity
x AS SINGLE: y AS SINGLE: z AS SINGLE ' World Position
dx AS SINGLE: dy AS SINGLE: dz AS SINGLE ' Velocity
rot AS SINGLE: rotV AS SINGLE ' Rotation state
isSphere AS INTEGER
END TYPE
' Pre-calculate geometry
CONST S_RES = 10 ' Sphere resolution (Higher = smoother, but slower)
DIM SHARED SphereV((S_RES + 1) * (S_RES + 1)) AS Point3D
DIM SHARED CubeV(1 TO 8) AS Point3D
' Generate Sphere Vertices
n = 1
FOR lat = 0 TO S_RES
phi! = 3.14159 * lat / S_RES
FOR lon = 0 TO S_RES
theta! = 2 * 3.14159 * lon / S_RES
SphereV(n).x = SIN(phi!) * COS(theta!)
SphereV(n).y = COS(phi!)
SphereV(n).z = SIN(phi!) * SIN(theta!)
n = n + 1
NEXT
NEXT
' Generate Cube Vertices
DATA -1,1,1,1,1,1,1,-1,1,-1,-1,1,-1,1,-1,1,1,-1,1,-1,-1,-1,-1,-1
FOR i = 1 TO 8: READ CubeV(i).x, CubeV(i).y, CubeV(i).z: NEXT
' Create Entities
CONST MAX_OBJS = 20
DIM e(1 TO MAX_OBJS) AS Entity
FOR i = 1 TO MAX_OBJS
e(i).x = RND * 4 - 2: e(i).y = RND * 2 - 1: e(i).z = -5 - RND * 5
e(i).dx = (RND - 0.5) * 0.05: e(i).dy = (RND - 0.5) * 0.05: e(i).dz = (RND - 0.5) * 0.05
e(i).rotV = RND * 0.1: e(i).isSphere = (RND > 0.5)
NEXT
' Main Loop
DO
_LIMIT 60: CLS
FOR i = 1 TO MAX_OBJS
' Move and Bounce
e(i).x = e(i).x + e(i).dx: e(i).y = e(i).y + e(i).dy: e(i).z = e(i).z + e(i).dz
IF ABS(e(i).x) > 3 THEN e(i).dx = -e(i).dx
IF ABS(e(i).y) > 2 THEN e(i).dy = -e(i).dy
IF e(i).z > -2 OR e(i).z < -12 THEN e(i).dz = -e(i).dz
e(i).rot = e(i).rot + e(i).rotV
' Render Object
IF e(i).isSphere THEN DrawSphere e(i), tex& ELSE DrawCube e(i), tex&
NEXT
_DISPLAY
LOOP UNTIL INKEY$ = CHR$(27)
CubeIndices: DATA 1,2,3,4,6,5,8,7,5,1,4,8,2,6,7,3,5,6,2,1,4,3,7,8
SUB DrawSphere (ent AS Entity, img&)
FOR lat = 0 TO S_RES - 1
FOR lon = 0 TO S_RES - 1
idx = lat * (S_RES + 1) + lon + 1
' Map 4 points of a sphere segment
DrawTri SphereV(idx), SphereV(idx + 1), SphereV(idx + S_RES + 1), ent, img&
DrawTri SphereV(idx + 1), SphereV(idx + S_RES + 2), SphereV(idx + S_RES + 1), ent, img&
NEXT
NEXT
END SUB
SUB DrawCube (ent AS Entity, img&)
' Simplistic Cube Draw using vertex indices
RESTORE CubeIndices: FOR f = 1 TO 6: READ v1, v2, v3, v4
DrawTri CubeV(v1), CubeV(v2), CubeV(v3), ent, img&
DrawTri CubeV(v1), CubeV(v3), CubeV(v4), ent, img&
NEXT: END SUB
SUB DrawTri (p1 AS Point3D, p2 AS Point3D, p3 AS Point3D, ent AS Entity, img&)
DIM rP(1 TO 3) AS Point3D: rP(1) = p1: rP(2) = p2: rP(3) = p3
FOR i = 1 TO 3
' Rotate and Offset
x = rP(i).x: y = rP(i).y: z = rP(i).z
nx = x * COS(ent.rot) - z * SIN(ent.rot): nz = x * SIN(ent.rot) + z * COS(ent.rot)
rP(i).x = nx + ent.x: rP(i).y = y + ent.y: rP(i).z = nz + ent.z
NEXT
' _MAPTRIANGLE without flags renders both sides (solid or wireframe effect depending on texture)
_MAPTRIANGLE (0, 0)-(255, 0)-(128, 255), img& TO(rP(1).x, rP(1).y, rP(1).z)-(rP(2).x, rP(2).y, rP(2).z)-(rP(3).x, rP(3).y, rP(3).z)
END SUB
If you ask it to add comments step by step it will, and also it make you anything you want!
john

