Author Topic: How to change color of a label in OpenGL ?  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

chrisc

  • Guest
How to change color of a label in OpenGL ?
« on: April 13, 2018, 04:25:21 PM »
i modified the sample cubicsphere.o2bas to become Cubicsphere2.o2bas
by adding some labels and remove some objects as shown in the image below.

but i couldn't change the color of the text label and also there is a dash line at the bottom
of the screen.  can some one help to resolve these problems? 

thanxx in advance

Code: [Select]
  $ title "Cubic sphere2"
  $ FileName "Cubicsphere2.exe"
 uses RTL64
$ fontA     "Arial",FW_SEMIBOLD

  % ExplicitMain
  % MultiSamples 4 '0..4..16
  include "OpenglSceneFrame.inc"



  uses shapes
  uses materials

  uses glo2\textures
  uses particles
  uses MinMidi

  indexbase 1
  float ang1
  int   cube,sphere,helix,tors,csface
  sys hmo 'midi
  Cloud cloud1
  Smoke smoke1
  Plant fern

  sub InitMidi()
  ================
  int er
  er=midiOutOpen(hmo, 0, 0, 0, CALLBACK_NULL) '0=synth a 2=soft synth
  midiOutShortMsg(hmo, 0xC0+0x0D00)           'Xylophone Bells assign
  end sub

  function ding(int v,n)
  ======================
  if v>127 then v=127
  if v<10 then v=10
  'midiOutShortMsg(hmo, v*0x10000+n*0x100+0x89) 'percussion off
  midiOutShortMsg(hmo, v*0x10000+n*0x100+0x99) 'percussion on
  end function


  sub initialize(sys hWnd)
  ========================
  '
  InitMidi
  GDIplus 1
  '
  static sys p,res=256
  BuildTextures 16,res
  p=fern.new res,32000 'pixel map
  MakeTexture p,res,res,texn[12]
  fern.free

  'cube=CompileList   : CubeForm      : glEndList
  sphere=CompileList : Spheric 1,1,6 : glEndList
  '
  SetTimer hWnd,1,10,null
  end sub


  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  DeleteTextures  16
  Gdiplus         0
  killTimer       hwnd, 1
  MidiOutClose    hmo
  end sub

  sub RenderPlane(int tex, float u,v)
  ===================================
  glBindTexture GL_TEXTURE_2D,tex
  glBegin GL_QUADS
  glTexCoord2f 0.0,0.0 : glVertex3f -1.0,0,-1.0
  glTexCoord2f u  ,0.0 : glVertex3f  1.0,0,-1.0
  glTexCoord2f u  ,v   : glVertex3f  1.0,0, 1.0
  glTexCoord2f 0.0,v   : glVertex3f -1.0,0, 1.0   
  glend
  end sub


  sub scene(sys hWnd)
  ===================
  '
  static single ra,ri
'  increase angle to increase rotation speed
  static  angi1=5
  '
  ActiveFrame
 ' glClearColor 0.5, 0.5, 0.7, 0
  glClearColor 0, 224, 200, 0
  StandardLighting li


  '  texture type -- see glo2\textures.inc
  int t1=texn[10]     '  marble
  int t2=texn[11]      ' green plane

  '  soft intense shadow texture   texn[5]  -- gives a translucent texture

'  ' display the text label1
  glPushMatrix
'  gltranslatef  -1.5,0.,-1.0
    gltranslatef  -.5,0.,-1.0
 ' glscalef      .25,.3,.01
  glScalef( 0.15, 0.2, .01)
 ' glColor3f     .99,.99,.00
 glColor3f     255,127,80
  gprint        "My Product"

 ' display the text label2
  glPushMatrix
    gltranslatef  -.5, -1.5,-1.0
 ' glscalef      .25,.3,.01
   glScalef( 0.15, 0.2, .01)
'  glColor3f     .99,.99,.00
  gprint        "Label 2"


 


  '
  'TILES   **************************
  glPushMatrix
  glEnable GL_TEXTURE_2D
  glTranslatef -8.0,-1.99,-5.0
  glScalef     .25,1.,.25
  glPushMatrix
  int i,j
  for j=1 to 16
    for i=1 to 16
      RenderPlane  t1,1.,1.
      glTranslatef 4.,0.,0.
    next
    glTranslatef -62.,0.,-2.
  next
  glPopMatrix
  glDisable GL_TEXTURE_2D
  glPopMatrix


 
  '
  '  RING  -- torus  ---------------------------------------------
  GoldMaterial.act
  'glEnable GL_TEXTURE_2D
  'glBindTexture GL_TEXTURE_2D,texn[2]
  glPushMatrix
  glTranslatef 2.6,1.8,-6.0
  'glrotatef -45.,0,1,0
  'glrotatef 90.0,1,0,0
  glScalef      .75,1.00,.75
  if not tors
    tors=CompileList : torus 1.,.20 : glEndList
  end if
  glCallList tors
  glPopMatrix
  glDisable GL_TEXTURE_2D



  '
  'METALLIC ORBS   ---------------------------
  glPushMatrix
  glTranslatef 0.5,-1.5,-8.0
  glScalef      .25,.25,.25
  SilverMaterial.act
  glCallList sphere
  glPopMatrix
  '
  glPushMatrix
  glTranslatef 1.0,-1.5,-9.0
  glScalef      .25,.25,.25
  SteelMaterial.act
  glCallList sphere
  glPopMatrix


  '
  'GLOBE  -- rotating globe in the middle  --------------------
  if not csface
    csface=CompileList
    CubicFace 8
    glEndList
  end if
  glPushMatrix
  glTranslatef -1.0,0.,-6.0
  glRotatef ang1,0,1,0
  'RedShinyMaterial.act
  'whiteMaterial.act
  GoldMaterial.act
 '  texture is needed to show rotation
   glEnable GL_TEXTURE_2D
 '  using
   glBindTexture GL_TEXTURE_2D, texn[10]           't2   'texn(3)
  glCallList csface
  glRotatef 90.0,0,1,0
    glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,1,0,0
  glCallList csface
  glRotatef 180.0,1,0,0 'top
  glCallList csface
  glPopMatrix
   glDisable GL_TEXTURE_2D

  '

 
  '
  'CONE
  glPushMatrix
  SilverMaterial.act
  glTranslatef -1.1,-2.,-6.0
  glScalef    .5,.5,.5
 ' glBindTexture GL_TEXTURE_2D,t1
  ConeFaces 16,0.,2.,0.
  glPopMatrix


 

 

 
 
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW



chrisc

  • Guest
Re: How to change color of a label in OpenGL ?
« Reply #1 on: April 13, 2018, 06:17:46 PM »
amended the program to eliminate the dash line

but still couldn't change the label colors ?

Code: [Select]
  $ title "Cubic sphere2"
  $ FileName "Cubicsphere2.exe"
 uses RTL64
$ fontA     "Arial",FW_SEMIBOLD

  % ExplicitMain
  % MultiSamples 4 '0..4..16
  include "OpenglSceneFrame.inc"



  uses shapes
  uses materials

  uses glo2\textures
  uses particles
  uses MinMidi

  indexbase 1
  float ang1
  int   cube,sphere,helix,tors,csface
  sys hmo 'midi






  sub InitMidi()
  ================
  int er
  er=midiOutOpen(hmo, 0, 0, 0, CALLBACK_NULL) '0=synth a 2=soft synth
  midiOutShortMsg(hmo, 0xC0+0x0D00)           'Xylophone Bells assign
  end sub

  function ding(int v,n)
  ======================
  if v>127 then v=127
  if v<10 then v=10
  'midiOutShortMsg(hmo, v*0x10000+n*0x100+0x89) 'percussion off
  midiOutShortMsg(hmo, v*0x10000+n*0x100+0x99) 'percussion on
  end function


  sub initialize(sys hWnd)
  ========================
  '
  InitMidi
  GDIplus 1
  '
  static sys p,res=256
  BuildTextures 16,res


  'cube=CompileList   : CubeForm      : glEndList
  sphere=CompileList : Spheric 1,1,6 : glEndList
  '
  SetTimer hWnd,1,10,null
  end sub


  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  DeleteTextures  16
  Gdiplus         0
  killTimer       hwnd, 1
  MidiOutClose    hmo
  end sub





 

  sub scene(sys hWnd)
  ===================
  '
  static single ra,ri
'  increase angle to increase rotation speed
  static  angi1=5
  '
  ActiveFrame
 ' glClearColor 0.5, 0.5, 0.7, 0
  glClearColor 0, 224, 200, 0
  StandardLighting li


  '  texture type -- see glo2\textures.inc
  int t1=texn[10]     '  marble
  int t2=texn[11]      ' green plane

  '  soft intense shadow texture   texn[5]  -- gives a translucent texture

'  ' display the text label1
  glPushMatrix
'  gltranslatef  -1.5,0.,-1.0
    gltranslatef  -.5,0.,-1.0
 ' glscalef      .25,.3,.01
  glScalef( 0.15, 0.2, .01)
 ' glColor3f     .99,.99,.00
 glColor3f     255,127,80
  gprint        "My Product"

 ' display the text label2
  glPushMatrix
    gltranslatef  -.5, -1.5,-1.0
 ' glscalef      .25,.3,.01
   glScalef( 0.15, 0.2, .01)
'  glColor3f     .99,.99,.00
  gprint        "Label 2"


 
 'TILES   **************************
  glPushMatrix
  glEnable GL_TEXTURE_2D
  glTranslatef -8.0,-1.99,-5.0
  glScalef     .25,1.,.25
  glPushMatrix
  int i,j
  for j=1 to 16
    for i=1 to 16
  '    this line below can display a dash line at
'     the bottom of the screen -- hence it is commented out
   '   RenderPlane  t1,1.,1.
      glTranslatef 4.,0.,0.
    next
    glTranslatef -62.,0.,-2.
  next
  glPopMatrix
  glDisable GL_TEXTURE_2D
  glPopMatrix

 

 
  '
  '  RING  -- torus  ---------------------------------------------
  GoldMaterial.act
  'glEnable GL_TEXTURE_2D
  'glBindTexture GL_TEXTURE_2D,texn[2]
  glPushMatrix
  glTranslatef 2.6,1.8,-6.0
  'glrotatef -45.,0,1,0
  'glrotatef 90.0,1,0,0
  glScalef      .75,1.00,.75
  if not tors
    tors=CompileList : torus 1.,.20 : glEndList
  end if
  glCallList tors
  glPopMatrix
  glDisable GL_TEXTURE_2D



  '
  'METALLIC ORBS   ---------------------------
  glPushMatrix
  glTranslatef 0.5,-1.5,-8.0
  glScalef      .25,.25,.25
  SilverMaterial.act
  glCallList sphere
  glPopMatrix
  '
  glPushMatrix
  glTranslatef 1.0,-1.5,-9.0
  glScalef      .25,.25,.25
  SteelMaterial.act
  glCallList sphere
  glPopMatrix


  '
  'GLOBE  -- rotating globe in the middle  --------------------
  if not csface
    csface=CompileList
    CubicFace 8
    glEndList
  end if
  glPushMatrix
  glTranslatef -1.0,0.,-6.0
  glRotatef ang1,0,1,0
  'RedShinyMaterial.act
  'whiteMaterial.act
  GoldMaterial.act
 '  texture is needed to show rotation
   glEnable GL_TEXTURE_2D
 '  using
   glBindTexture GL_TEXTURE_2D, texn[10]           't2   'texn(3)
  glCallList csface
  glRotatef 90.0,0,1,0
    glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,0,1,0
  glCallList csface
  glRotatef 90.0,1,0,0
  glCallList csface
  glRotatef 180.0,1,0,0 'top
  glCallList csface
  glPopMatrix
   glDisable GL_TEXTURE_2D

  '

 
  '
  'CONE
  glPushMatrix
  SilverMaterial.act
  glTranslatef -1.1,-2.,-6.0
  glScalef    .5,.5,.5
 ' glBindTexture GL_TEXTURE_2D,t1
  ConeFaces 16,0.,2.,0.
  glPopMatrix


 

 

 
 
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW


Charles Pegge

  • Guest
Re: How to change color of a label in OpenGL ?
« Reply #2 on: April 13, 2018, 07:33:31 PM »
Hi Chris,

 glColor3ub     255,127,80

but the native Graphics-hardware type is float, so I always use the 3f calls with a range 0.0..1.0

chrisc

  • Guest
Re: How to change color of a label in OpenGL ?
« Reply #3 on: April 13, 2018, 09:39:16 PM »

 glColor3ub     255,127,80

did not work, there must some other way to place the labels in order to display the colors

Mike Lobanovsky

  • Guest
Re: How to change color of a label in OpenGL ?
« Reply #4 on: April 13, 2018, 11:21:07 PM »
Chris,

1. Prefer to use float functions and parameters when dealing with OpenGL. Single-precision floating-point is its native internal format, and all other formats just lose time converting the other numeric types to their intrinsic float representation.

2. OpenGL material colors are only effective when scene lighting is disabled. When lighting is on, the light colors usually override the material color settings. Thus,
Code: [Select]
........
 glColor3f 0.0, 0.0, 1.0
 glDisable GL_LIGHTING
 gPrint    "Your Product"
 glEnable  GL_LIGHTING
........
 glColor3f 1.0, 0.0, 0.0
 glDisable GL_LIGHTING
 gPrint    "Label 2"
 glEnable  GL_LIGHTING
........
will produce the attached image.

3. Oxygen mostly uses legacy OpenGL to implement its example scripts and engines. Start with the classical OpenGL Redbook to learn the basics of OpenGL colors, lights, and materials. Then work your way through three or more books to reach the bleeding edge of modern OpenGL, OpenGL Superbible 7th edition. :)

chrisc

  • Guest
Re: How to change color of a label in OpenGL ?
« Reply #5 on: April 14, 2018, 07:16:36 AM »
Thanxx a lot Mike
it is working now