Beginner-questions

BlitzMax Forums/BlitzMax OpenGL Programming/Beginner-questions

Ok, i editted my post here. I got some things working, even though i don't exactly know why certain things occur as they do. I'm just moving along, hoping i'll find them out later on.

Anyway: i'm trying to figure out how to have my quads get opacity. i read tutorials, examples but can't find out why i don't get any results in that direction.

i used
glEnable(GL_BLEND)
glColor4f(1.0,0,0,0.21)
glBlendFunc (GL_SRC_ALPHA, L_ONE_MINUS_SRC_ALPHA)

Is there more i should take care of before any alpha on my quads will work?

(apologies for the bad title - can't seem to fix that anymore)

Global ScreenWidth:Int=800
Global ScreenHeight:Int=600
Global ScreenDepth:Int=16

GLGraphics ScreenWidth,ScreenHeight


init()

Global pos_x# = 0
Global pos_y# = 0
Global pos_z# = 0

Global objectList:TList=CreateList()


createCubes(10)


While Not KeyHit( KEY_ESCAPE )

	glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT 
	glLoadIdentity
	
	checkKeys()


	' eigen positie 
	xtrans# = -pos_x#
	ytrans# = -pos_y#
	ztrans# = -pos_z#		
	
	
	glTranslatef xtrans#, ytrans#, ztrans#

	For current_cube:cube = EachIn objectList

		px# = current_cube.posX#
		py# = current_cube.posY#
		pz# = current_cube.posZ#

		rx# = current_cube.rotX#
		ry# = current_cube.rotY#
		rz# = current_cube.rotZ#
		

		glPushMatrix()
		glTranslatef px#,py#,pz#
		glRotatef rx#,1,0,0

		drawCube(0.5)			
		glPopMatrix()		
		
		current_cube.rotX# = current_cube.rotX# + 4
	Next	
	
	Flip

Wend

Function init()
	glClearColor(0.9, 0.9, 0.9, 0.0)
'	glClearDepth 1.0
'	glDepthFunc(GL_LESS)
'	glDisable(GL_DEPTH_TEST)
	glEnable(GL_BLEND)
'	glShadeModel(GL_SMOOTH)
	glViewport(0,0,ScreenWidth,ScreenHeight)
	glMatrixMode(GL_PROJECTION)
	glLoadIdentity()
	gluPerspective(45.0,Float(ScreenWidth)/Float(ScreenHeight),1.0,100.0)
	glMatrixMode(GL_MODELVIEW)
End Function

Function checkKeys()

	speed# = .1
	
	' MOVEMENT
	
	If KeyDown (KEY_UP)
		pos_z# = pos_z# - speed#
	End If
	If KeyDown (KEY_DOWN)
		pos_z# = pos_z# + speed#
	End If
	If KeyDown (KEY_LEFT)
		pos_x# = pos_x# - speed#
	End If
	If KeyDown (KEY_RIGHT)
		pos_x# = pos_x# + speed#
	End If
	If KeyDown (KEY_Q)
		pos_y# = pos_y# + speed#
	End If
	If KeyDown (KEY_A)
		pos_y# = pos_y# - speed#
	End If
	


	'DebugLog (pos_x#+"  "+pos_y#+"  "+pos_z#)
End Function


Function drawCube(size#)

	glBegin GL_QUADS
	
		halve# = size# / 2.0
		glColor4f(1.0,0,0,0.21)
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
		
	
		'achterkant
		glVertex3f -halve#, halve#, -halve#					'Top Left
		glVertex3f  halve#, halve#, -halve#					'Top Right
		glVertex3f  halve#,-halve#, -halve#				'Bottom Right
		glVertex3f -halve#,-halve#, -halve#					'Bottom Left

		'voorkant
		glVertex3f -halve#, halve#, halve#					'Top Left
		glVertex3f  halve#, halve#, halve#					'Top Right
		glVertex3f  halve#,-halve#, halve#				'Bottom Right
		glVertex3f -halve#,-halve#, halve#					'Bottom Left


		'linkerkant
		glVertex3f -halve#, halve#, halve#					'Top Left
		glVertex3f -halve#,-halve#, halve#
		glVertex3f -halve#,-halve#, -halve#				'Bottom Left
		glVertex3f -halve#, halve#, -halve#				'Bottom Right
		
		'rechterkant
		glVertex3f halve#, halve#, halve#					'Top Left
		glVertex3f halve#,-halve#, halve#
		glVertex3f halve#,-halve#, -halve#				'Bottom Left
		glVertex3f halve#, halve#, -halve#				'Bottom Right
		
		'onderkant
		glVertex3f -halve#,-halve#, halve#					'Top Left
		glVertex3f -halve#,-halve#, -halve#
		glVertex3f halve#,-halve#, -halve#				'Bottom Left
		glVertex3f halve#,-halve#, halve#				'Bottom Right
		
		'bovenkant
		glVertex3f -halve#,halve#, halve#					'Top Left
		glVertex3f -halve#,halve#, -halve#
		glVertex3f halve#,halve#, -halve#				'Bottom Left
		glVertex3f halve#,halve#, halve#				'Bottom Right
		
	glEnd
End Function


Function createCubes(num%)

	For n=1 To num%
		div# = .5
	
		obj:cube = New cube
'		obj.posX# = Rnd(-div#,div#)
'		obj.posY# = Rnd(0,div#)
'		obj.posZ# = Rnd(-div#,0)
		
		obj.posX# = n
		obj.posY# = 0
		obj.posZ# = -6
		
		obj.rotX# = 0.4
		obj.rotY# = 0.0
		obj.rotZ# = 0.0			


		ListAddLast objectList, obj
	
		DebugLog CountList(objectList)
	Next
End Function

Type cube
	Field posX#
	Field posY#	
	Field posZ#	
	
	Field rotX#
	Field rotY#	
	Field rotZ#	
	
End Type


You can't call GLBlendFunc inside a GLBegin...GLEnd block. Move it above GLBegin and it works.

thank you, that works indeed.

my alpha-values have some effect now, although i'm not getting the results i wanted. how would i get a cube that you can see through slightly? i get a 1-color-solid version of the cube, but expected for example to be able to see faces at the rear of the cube (by looking through the front ones).

Alpha ranges from zero to 1. Keep in mind two of the faces (at least) will overlap and make the cube seem less transparent. Try drawing a busy background behind it.

I'd like to be able to use this for zooming in my project. But I have a bit of difficulty understanding certain things for opengl.

if I set my graphics with GLGraphics, it returns null object for the first image it tries to load. Setting it back is fine.

If i use this code as is and I load and draw an image in it, it returns null object when I run it, if i change glgraphics to graphics it works and it draws a black screen with my image only.

ive set my graphics driver to opengl in my project, why won't this stuff work with graphics. and why when i use GLgraphics in my app does it not work.

can this work to tanslate the z of normal drawn images in max? or in tanslatef on the z coordinate only works because he is using opengl cubes...

and i think someone said somewhere that max images are quads, so they should be able to go in and out of the screen right?

gltanslatef is what i need, but i have no idea how to implement it, in the function i use in my project i call all the right things like the glprojection, glmodelview, glloadidentity, but my graphics just flicks right off the screen when i zoom.

You can use glColor4ub if you want to use values 0..255 without having to think what it is as a decimal of 1

that solves the problem i spoke of? :)