please someone help me

BlitzMax Forums/BlitzMax OpenGL Programming/please someone help me

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

ok, i did it... it succesfully compiled and run.. but not preview the right it should preview, so i assume something wrong with my conversion codes i did.. please check bmax conversion here (i just the mouse codes and animation codes, just dull l, k, m, n, z and x, btw q for quit)..

p/s im not using glut at all coz bmax do it all for me.. but i dont know i am doing it right

Global g_ViewMode:Int

Global currentL:Int, currentM:Int
Global iXWinPos:Int, iYWinPos:Int

Global iYAngle:Int, iYBegin:Int
Global iXAngle:Int, iXBegin:Int

Global iDisplayWidth:Int, iDisplayHeight:Int

Global iMovingStatus:Int

Global iAnimatingStatus:Int

Global iResolution:Int

Global scaleLevel:Double

Global Quit:Byte

currentM = 0
currentL = 0
	
iDisplayWidth = 640
iDisplayHeight = 480
	
iYAngle = 0
iYBegin = 0
iXAngle = 0
iXBegin = 0
	
iMovingStatus = 0
	
iAnimatingStatus = 0
	
iYWinPos = 10
iXWinPos = 10

g_ViewMode = GL_LINE
	
iResolution = 64
	
scaleLevel = 1.0

bglCreateContext iDisplayWidth,iDisplayHeight,0,0,BGL_BACKBUFFER | BGL_DEPTHBUFFER

initOpenGL

While Not Quit

	displayScene
	keyboard
	
	FlushMem
Wend
End

Function keyboard()
	If KeyHit(key_L)
		If currentL > 0
			If Abs(currentM) = currentL
				If currentM < 0 Then currentM :+ 1
				If currentM > 0 Then currentM :- 1
			EndIf
			currentL :- 1
		EndIf
	EndIf
	If KeyHit(Key_M)
		If currentM > 0 Or (currentM <= 0 And (-currentM < currentL)) Then currentM :- 1
	EndIf
	If KeyHit(Key_R)
		If iResolution > 16 Then iResolution :- 1
	EndIf
	If KeyHit(Key_Z)
		If scaleLevel > 0.1 Then scaleLevel :- 0.1
	EndIf
	If KeyHit(Key_Y)
		If g_ViewMode = GL_FILL
			g_ViewMode = GL_LINE
		ElseIf g_ViewMode = GL_LINE
			g_ViewMode = GL_POINT
		ElseIf g_ViewMode = GL_POINT
			g_ViewMode = GL_FILL
		Else
			g_ViewMode = GL_FILL
		EndIf
		glPolygonMode GL_FRONT_AND_BACK,g_ViewMode
	EndIf
	If KeyHit(Key_K) Then currentL :+ 1
	If KeyHit(Key_N)
		If currentM < currentL Then currentM :+ 1
	EndIf
	If KeyHit(Key_T) Then iResolution :+ 1
	If KeyHit(Key_X) Then scaleLevel :+ 0.1
	If KeyHit(Key_Q) Then Quit = True
EndFunction

Function displayScene()
	Local glfMaterialColor:Float[] = [0.0,0.0,1.0,1.0]
	
	glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
	
	glMatrixMode GL_PROJECTION
	glLoadIdentity
	gluPerspective 60,1.3333,0.01,30

	glMatrixMode GL_MODELVIEW
	glLoadIdentity
	gluLookAt 0.0,-3.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0
	
	glRotatef iXAngle,1.0,0.0,0.0
	glRotatef iYAngle,0.0,0.0,1.0
	
	glMaterialfv GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,glfMaterialColor
	glEnable GL_COLOR_MATERIAL
	renderSH(iResolution,0.0,0.0,0.0,currentL,currentM,scaleLevel)
	
	bglSwapBuffers
EndFunction

Function initOpenGL()
	glEnable GL_DEPTH_TEST
	
	glEnable GL_COLOR_MATERIAL
	
	glShadeModel GL_SMOOTH
	
	glEnable GL_NORMALIZE
	
	glHint GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST
	
	glPolygonMode GL_FRONT_AND_BACK,GL_LINE
	
	glEnable GL_LIGHTING
	glEnable GL_LIGHT0
EndFunction

Function renderSH(iSteps:Int,x:Double,y:Double,z:Double,l:Int,m:Int,scale:Double)
	Local i:Int, j:Int
	
	Local theta:Double, phi:Double
	
	Local step_theta:Double, step_phi:Double
	
	Local R:Double
	
	step_theta = Pi/iSteps
	step_phi = 2*Pi/iSteps
	
	glPushMatrix
		glTranslatef x,y,z
	
		glScalef scale,scale,scale
	
		For i = 0 Until iSteps
			theta = step_theta*i
			For j = 0 Until iSteps
				phi = step_phi*j
			
				glBegin GL_QUADS
					R = evaluateSH(l,m,theta,phi)
					glNormal3f R*Sin(phi)*Cos(theta),R*Sin(phi)*Sin(theta),R*Cos(phi)
					glVertex3f R*Sin(phi)*Cos(theta),R*Sin(phi)*Sin(theta),R*Cos(phi)
					
					R = evaluateSH(l,m,theta + step_theta,phi)
					glNormal3f R*Sin(phi)*Cos(theta + step_theta),R*Sin(phi)*Sin(theta + step_theta),R*Cos(phi)
					glVertex3f R*Sin(phi)*Cos(theta + step_theta),R*Sin(phi)*Sin(theta + step_theta),R*Cos(phi)
				
					R = evaluateSH(l,m,theta + step_theta,phi + step_phi)
					glNormal3f R*Sin(phi + step_phi)*Cos(theta + step_theta),R*Sin(phi + step_phi)*Sin(theta + step_theta),R*Cos(phi + step_phi)
					glVertex3f R*Sin(phi + step_phi)*Cos(theta + step_theta),R*Sin(phi + step_phi)*Sin(theta + step_theta),R*Cos(phi + step_phi)
					
					R = evaluateSH(l,m,theta,phi + step_phi)
					glNormal3f R*Sin(phi + step_phi)*Cos(theta),R*Sin(phi + step_phi)*Sin(theta),R*Cos(phi + step_phi)
					glVertex3f R*Sin(phi + step_phi)*Cos(theta),R*Sin(phi + step_phi)*Sin(theta),R*Cos(phi + step_phi)
				glEnd
			Next
		Next
	glPopMatrix
EndFunction

Function doubleFactorial:Int(x:Int)
	Local result:Int
	
	If x = 0 Or x = -1 Then Return 1
	result = x

	x :- 2
	While x > 0
		result :* x
		x :- 2
	Wend

	Return result
EndFunction

Function factorial:Int(x:Int)
	Local result:Int
	
	If x = 0 Or x = -1 Then Return 1
	
	result = x
	x :- 1
	While x > 0
		result :* x
		x :- 1
	Wend
	
	Return result
EndFunction

Function ALPStd:Double(x:Double,l:Int,m:Int)
	If l = m Then Return (-1^m)*doubleFactorial(2*m - 1)*(Sqr(1 - x*x)^m)
	If l = (m + 1) Then Return x*(2*m + 1)*ALPStd(x,m,m)
	Return (x*(2*l - 1)*ALPStd(x,l - 1,m) - (l + m - 1)*ALPStd(x,l - 2,m))/(l - m)
EndFunction

Function evaluateK:Double(l:Int,m:Int)
	Local result:Double
	
	result = ((2.0*l + 1.0)*factorial(l - m))/(4*Pi*factorial(l + m))
	
	Return Sqr(result)
EndFunction

Function evaluateSH:Double(l:Int,m:Int,theta:Double,phi:Double)
	Local SH:Double = 0.0
	
	If m = 0
		SH = evaluateK(l,0)*ALPStd(Cos(theta),l,0)
	ElseIf m > 0
		SH = Sqr(2)*evaluateK(l,m)*Cos(m*phi)*ALPStd(Cos(theta),l,m)
	Else
		SH = Sqr(2)*evaluateK(l,-m)*Sin(-m*phi)*ALPStd(Cos(theta),l,-m)
	EndIf
	
	Return SH
EndFunction