02-11-2001, 03:28 PM
I've been placing several primitive shapes on the screen, setting them all into motion (isolated rotation directions) and then blasting them with full diffuse- and specular light. Basically works Ok...
The problem I have is this: eventhough I re-apply the light every time in FormPaint, it still seems that the colors are calculated only once when the screen is initialized; it's as if there was a separate lamp rotating alongside each primitive. How can I re-draw the light based on the new object alignments?
check out the faq link on this sites homepage
if objects are changing shapes u need to recalculate the normals
if the viewers position has changed u will need to reposition the light after the camera change
02-12-2001, 01:33 PM
I was only vaguely aware of the importance of re-positioning the light every time, but it appears that I've been doing it all the time by coincidence. It still won't work, and the shapes are not deformed or anything. You can download a demonstration from:
Here's some example code; I'm using Delphi at the moment, although I'll probably soon move to C++. I hope it doesn't matter that much... using Delphi, I mean.
By the way, I would also greatly appreciate any help with exporting this stuff into web-deployed ActiveX; I managed to do it once, but usually OpenGL starts drawing before the IE Device Context becomes available, and I have no idea how to fix that.
procedure TForm1.FormPaint(Sender: TObject);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glTranslatef(2.2, 1.8, 2.3);
// Various push-pops and geometry drawing
...and the light-class draw method looks like this. Note that I'm using two-sided material colouring and lighting since many of the primitives are at least partially open.
if FActive then begin
end else begin
glLightfv(FSource, GL_POSITION, @FLocation);
glLightfv(FSource, GL_DIFFUSE, @FDiffuse);
glLightfv(FSource, GL_SPECULAR, @FSpecular);
if FSpotLight then begin
glLightfv(FSource, GL_SPOT_CUTOFF, @FCutOff);
glLightfv(FSource, GL_SPOT_DIRECTION, @FDirect);
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.