|
Post by Nicky Peter Hollyoake on Oct 24, 2014 20:05:06 GMT -5
without making the squares smaller and making more is there any way, or what would be the best way to make the light smoother? I'm hoping it's possible, or I have to modify most of my game to deal with this.
'// spot light test // glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glLightfv(GL_LIGHT0, GL_DIFFUSE, Vec4(1, 1, 1, 1)) glLightfv(GL_LIGHT0, GL_AMBIENT, Vec4(0.1, 0.1, 0.1, 1)) glLightfv(GL_LIGHT0, GL_SPECULAR, Vec4(0.9, 0.9, 0.9, 1)) glLightfv(GL_LIGHT0, GL_POSITION, Vec4(0, 0, 5, 1)) glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 2) glMaterialfv(GL_FRONT, GL_DIFFUSE, vec4(1, 1, 1, 1)) glMaterialfv(GL_FRONT, GL_AMBIENT, vec4(1, 0, 0, 1))
dim x, y dim mx#, my#, s#=5
while true glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) mx# = mouse_x() * 2 my# =-mouse_y() * 2 s# = s# + mouse_wheel() glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, vec3(-1+mx#, 1+my#, -1)) glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, s#)
for y = 0 to 19 for x = 0 to 19 glPushMatrix() glTranslatef(x-10, y-10, -30) glBegin(GL_QUADS) glVertex2f(-1,-1) glVertex2f(-1, 1) glVertex2f( 1, 1) glVertex2f( 1,-1) glEnd() glPopMatrix() next next swapbuffers() wend
- Nicky
|
|
|
Post by matthew on Oct 26, 2014 8:08:57 GMT -5
Don't you have to use glNormals when you want to light something correctly, or aren't they relevant here?
|
|
|
Post by Nicky Peter Hollyoake on Oct 27, 2014 21:40:56 GMT -5
No, glNormal isn't relevant here. My problem is the lighting is being effected per face, can you change it to per vertex/pixel? If not I have to make 10s/100s of little squares to pull off a nice effect. I heard of something called OpenGL projected texture? Anyone know anything that can direct me with more information about that? Done some searches but nothing that helps much. It's for a torch I'm making in 2D (Birds view).
- Nicky
EDIT: Here's closer to what I want but you can still see the faces...
'// spot light test // glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glLightfv(GL_LIGHT0, GL_DIFFUSE, Vec4(1, 1, 1, 1)) glLightfv(GL_LIGHT0, GL_AMBIENT, Vec4(0.1, 0.1, 0.1, 1)) glLightfv(GL_LIGHT0, GL_SPECULAR, Vec4(0.9, 0.9, 0.9, 1)) glLightfv(GL_LIGHT0, GL_POSITION, Vec4(0, 0, 5, 1)) glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 100) glMaterialfv(GL_FRONT, GL_DIFFUSE, vec4(1, 1, 1, 1)) glMaterialfv(GL_FRONT, GL_AMBIENT, vec4(1, 0, 0, 1))
dim x, y dim mx#, my#, s#=15
while true glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) mx# = mouse_x() * 2 my# =-mouse_y() * 2 s# = s# + mouse_wheel() glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, vec3(-1+mx#, 1+my#, -1)) glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, s#) for y = 0 to 19 for x = 0 to 19 glPushMatrix() glTranslatef(x-10, y-10, -30) glBegin(GL_QUADS) glVertex2f(-1,-1) glVertex2f(-1, 1) glVertex2f( 1, 1) glVertex2f( 1,-1) glEnd() glPopMatrix() next next swapbuffers() wend
|
|
|
Post by matthew on Oct 28, 2014 3:58:03 GMT -5
There's an example of using torch-light in a 2d game here. However the designer has created a texture and just blended it to achieve the lighting effect, rather than use OpenGL lighting. As for lighting per vertex. Well you've already discovered that if you divide the quad into smaller quads you're just creating more vertexes which is why the lighting looks better. :-)
|
|
|
Post by DJLinux on Oct 28, 2014 12:45:50 GMT -5
|
|