changing colors of vertices

BlitzMax Forums/BlitzMax Beginners Area/changing colors of vertices

Bremer(Posted 2005) [#1]
I have only just started looking at Bmax now that its released for PC, and here is my first question:

Framework BRL.BlitzGL
Import BRL.System
Import PUB.OpenGL
Import BRL.linkedlist
Strict

Const SCRX=1024,SCRY=768
Type color
 Field r#,g#,b#,a#
End Type

Type vec3
 Field x#,y#,z#
End Type

Local ambient:color = New color
ambient.r = 0.2
ambient.g = 0.5
ambient.b = 0.7
Local position:vec3 = New vec3
position.x = 5.0
position.y = 13.0
position.z = 15.0

Type points
	Field x#, y#
	Field R, G, B
End Type

Global list:TList=CreateList()
Local mo:points = New points
mo.x# = -1
mo.y# = -1
mo.r = 255
mo.g = 0
mo.b = 0
ListAddLast list,mo
mo:points = New points
mo.x# = 1
mo.y# = -1
mo.r = 0
mo.g = 255
mo.b = 0
ListAddLast list,mo
mo:points = New points
mo.x# = 1
mo.y# = 1
mo.r = 0
mo.g = 0
mo.b = 255
ListAddLast list,mo
mo:points = New points
mo.x# = -1
mo.y# = 1
mo.r = 255
mo.g = 255
mo.b = 255
ListAddLast list,mo

Global angle:Float = 0.5

' init OGL
bglCreateContext(SCRX, SCRY, 32, 0,BGL_BACKBUFFER|BGL_DEPTHBUFFER)
glViewport(0,0,SCRX,SCRY)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0,Float(SCRX)/Float(SCRY),1.0,100.0)

' create light and position it
glLightfv GL_LIGHT0, GL_AMBIENT, Varptr(ambient.r)
glLightfv GL_LIGHT0, GL_POSITION, Varptr(position.x)
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
' set render options
glShadeModel(GL_SMOOTH)
glEnable(GL_DEPTH_TEST)
glEnable(GL_CULL_FACE)
glMatrixMode(GL_MODELVIEW)
' move camera
glTranslatef(0.0,0.0,-20.0)

bglSetSwapInterval( 60 )

While Not KeyHit(KEY_ESCAPE)
 glRotatef(angle,0,0,1)
 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

glBegin(GL_QUADS)
For mo:points = EachIn list
	glColor3i( mo.r, mo.g, mo.b )
	glVertex3f( mo.x#, mo.y#, 0 )
Next
glEnd()

bglSwapBuffers()

Wend
End


In the above code, why doesn't the quad have the colors that I set?


ImaginaryHuman(Posted 2005) [#2]
Try glColor3b, it deosn't need to be an integer


Sweenie(Posted 2005) [#3]
Don't know why it doesn't work with Color3b or Color3i, but it will work if you use Color3f(the color values must be a number between 0.0 - 1.0)
Since you have light enabled you also need to call...
glEnable(GL_COLOR_MATERIAL)


Bremer(Posted 2005) [#4]
Yes it seem to work with Color3f , and I didn't know about the GL_COLOR_MATERIAL, so thats good to find out. I guess its back to my OpenGL Super Bible and read a few more chapters, :) Thanks for the help so far guys.