circa properties and Positionierung of light in OpenGL To understand, had I it me first visualisieren. the Result pieces I gladly with you.
there are a couple API Aufrufe thereby, its but everything very überschaubar held.
my Top 3 Learnings were: - Glanzlichter are still none so heavy - Platzierung of light is unabashed of Pushs and Pops - The Lichtgenauigkeit is directly from the Dreiecksanzahl tributary
$H OpenGL.ph
declare time&, frames%
declare rtri!, light#
declare white#,red#, green#,blue#, zero#, list&,loop&
dim light#,16
dim white#,16
dim red#,16
dim green#,16
dim blue#,16
dim zero#,16
FloatArray(white#,1,1,1,1)
FloatArray(red#,1,0,0,1)
FloatArray(green#,0,1,0,1)
FloatArray(blue#,0,0,1,1)
FloatArray(zero#,0,0,0,1)
FloatArray(light#,-0.05,-0.05,-0.05, 1.0)
PROC GRID
'there's better Opportunities, bars to create but for this example reicht it, one einzelner Quad would
'not sensible beleuchtet go (see die) "per-vertex lighting"
parameters size!, resolution!
if list& = 0
list& = ogl("StartList")
oGL("Move", -(size! * 0.5)-(size! / resolution! * 0.5),(size! * 0.5)-(size! / resolution! * 0.5), 0)
whileloop 1, int(resolution!)
oGL("Move", (size! / resolution!),-size!, 0)
loop& = &loop
whileloop 1, int(resolution!)
if ((&loop + loop&) MOD 2) = 0
oGL("Color", 0.2,0.2,0.2,1.0)
else
oGL("Color", 1.0,1.0,1.0,1.0)
endif
oGL("Move", 0.0, (size! / resolution!), 0)
oGL("Quad", (size! / resolution!),(size! / resolution!))
endwhile
endwhile
ogl("EndList")
endif
ogl("Drawlist", list&)
ENDPROC
Proc Light
'to better explanation in Proc gekapselt, if it circa performance goes takes one a finished area,
'Definition of everything from position would too once with Initialisierung wealthy, the Objekt serves the Visualisierung
'the Lichtposition. the Grundlicht (Ambient) is easy negative staid there it from irgendeinem reason with "0" yet something
'light gives
parameters no&, r!, g!, b!
declare color#
dim color#, 16
FloatArray(color#,r!, g!, b!, 1.0)
oGL("glMaterialfv", ~GL_FRONT_AND_BACK, ~GL_EMISSION, color#)
oGL("Color", r!, g!, b!, 1.0)
oGL("Cuboid", 0.15, 0.15, 0.15)
oGL("glMaterialfv", ~GL_FRONT_AND_BACK, ~GL_EMISSION, zero#)
oGL("glLightfv",~GL_LIGHT0 + no&,~GL_AMBIENT,light#)'GL_AMBIENT
oGL("glLightfv",~GL_LIGHT0 + no&,~GL_DIFFUSE, color#)' GL_DIFFUSE
oGL("glLightfv",~GL_LIGHT0 + no&,~GL_POSITION,zero#)' GL_POSITION
oGL("glLightfv",~GL_LIGHT0 + no&,~GL_SPECULAR, white#)' GL_SPECULAR
oGL("glEnable",~GL_LIGHT0 + no&)
dispose color#
Endproc
proc DrawGLScene
oGL("Clear")
oGL("Move", 0, 0.75, -5.0)
oGL("glMaterialfv",~GL_FRONT_AND_BACK, ~GL_SPECULAR, white#)' Glanzlichtfarbe
oGL("glMaterialf", ~GL_FRONT_AND_BACK, ~GL_SHININESS,128.0)' Glanzlichtgröße (large number is small, max 128.0)
oGL("glDisable",~GL_LIGHT0)'Default light from
'-------
'Lichtpositionen can not through Push/Pop kapseln!
'Jegliche Positionierung must means thereafter again negiert go, with Rotationen achsenweise
'and everything always in umgekehrter Order - a take of it in the Light()-function would imaginable
'LICHTER
oGL("Rotate",0,0, rtri!)
oGL("Move", 2.0, 0,0)
'Light(Lichtnummer, ruddy, green, blue)
Light(1,1,0,0)' ruddy
oGL("Move", -2.0, 0,0)
oGL("Rotate", 0,0,-rtri!)
oGL("Rotate",0,90,0)
oGL("Rotate",0,0, rtri!)
oGL("Move", 2.0, 0,0)
Light(2,0,1,0)' green
oGL("Move", -2.0, 0,0)
oGL("Rotate", 0,0,-rtri!)
oGL("Rotate", 0,-90,0)
oGL("Rotate", 0, rtri!,0)
oGL("Move", 2.5, 0,0)
Light(3,0,0,1)' blue
oGL("Move", -2.5, 0,0)
oGL("Rotate", 0, -rtri!,0)
'OBJEKTE
oGL("Color", 1, 1, 1, 1)
'something in the against herumschauen:
oGL("Rotate",sin(rtri!*0.01) * 10.0, sin(rtri!*0.01) * 20.0, sin(rtri!*0.01) * 5.0)
oGL("Push")'ground
oGL("Move", 0, -2.2, -4)
oGL("Rotate",270, 0,0)
GRID(20,40)
oGL("Pop")
oGL("Push")'die, only very eingeschränktes Lighting
oGL("Move", -0.65, 0.5, 0)
oGL("Rotate", -45, 45, 0)
oGL("Cuboid", 0.75, 0.75,0.75)
oGL("Pop")
oGL("Push")'bullet, with many Dreiecken siehts correctly. well from
oGL("Move", 1, 0, 0)
oGL("Sphere", 0.65, 192,192)
oGL("Pop")
oGL("Push")'cone / Cone
oGL("Move", 2.5, -1.5, -1.0)
oGL("Cylinder", 1.0, 0,2.0,192)
oGL("Pop")
oGL("Push")'Cylinder, sees too with few Unterteilungen that's all right from
oGL("Move", -2.0, -0.5, -1.5)
oGL("Rotate", -15, -30, 30)
oGL("Cylinder", 0.20, 0.20,4,30)
oGL("Pop")
oGL("Show")
rtri! = rtri! + 1
endproc
Proc FloatArray
parameters x&,a!,b!,c!,d!
long x&,0 = single(a!)
long x&,4 = single(b!)
long x&,8 = single(c!)
long x&,12 = single(d!)
Endproc
' Hauptprogramm
' -------------
declare end%
CLS 0
oGL("Init", %hWnd, 0,0,0,1)
oGL("PosMode", 1)
oGL("glEnable",~GL_CULL_FACE)
oGL("glEnable",~GL_DEPTH_TEST)
oGL("BlendMode", 1)
oGL("Fog", 3, 6, 14)
time& = &GetTickCount
frames% = 0
ende% = 0
WhileNot end%
'WaitInput ought to in 3D-Applications and play in each drop vermieden go,
'there there also without timer ca. 8 ms unkontrollierbar vanish
if isKey(27)
end% = 1
endif
DrawGLScene()
inc frames%
if &GetTickCount - time& >= 1000' 1 second is 'rum
setText %hWnd, st$(frames%) + " Frames/sek"
time& = &GetTickCount
frames% = 0
endif
EndWhile
end
|