OpenGl question 2d graphics

Started by Frank Brübach, February 04, 2025, 05:59:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

hi charles, how I can print the name of picked object in this scene? i have for example five different objects to Pick
thanks, frank


  '#compact
  % filename "t.exe"
 'uses RTL64

  % Title "graphicsOpgl Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  % fontA    "Arial",FW_SEMIBOLD

  uses ConsoleG

  sub main
  ========
  sys imgn2

  BeginPick
  PickLabel 0

  if opening then
    CreateTexture imgn,"kleinfuchs.jpg" ' butterfly
    'CreateTexture imgn2,"kuchen1.jpg"
  end if
  cls
  pushstate

    pushstate
      UserMovement m1,100,1
      move 5,-6
      color .50,.00,.70,1.0 : fan 5.,000. ,060. ,2.0 'wedge
      color .40,.50,.00,1.0 : fan 5.,060,120,2 'wedge
      color 1,1,0,1
      move .0,.0,.0001
      color .00,.00,.30,.5 : fan 3.,000,360,2 'transp overlay
      thickness 2
      color .90,.20,.00,.5 : arc 5,0,120,1
    popstate

    '
    move 0,0,.0002 'next layer
    '
    'FILE IMAGE
    pushstate
      move 11,-18.0
      UserMovement m2,200,1
      flat
      color 1,1,1,1
      texture imgn
      quadnorm 10.0,10.0*imgnHt/imgnWi 'apply image texture to quad
      texture 0
    popstate

    move 0,0,.0002 'next layer

    'GRID
    pushstate
      move 11,-18.0
      UserMovement m3,300,1
      thickness 1
      color 1,0,0,0
      color .0,.5,.7,1
      'grid 1.,20,10 'fine grid
      grid 1.,40,10 'fine grid

      thickness 3
      move .0,.0,.0001
      'grid 1.,20,10,5,1 'thick grid with pickable overlay
'      grid 1.,10,10,2,2
      grid 1.,40,10,5,2
    popstate

    move 0,0,.0002 'next layer
   
    pushstate
      move 0,-.5
      UserMovement m4,400,1
      scale 2
      printl "2D photos movements"
    popstate

  popstate

'------------------------------------- // 2

  if opening then
    CreateTexture imgn2,"kuchen1.jpg"
  end if
  cls
  'pushstate

  pushstate
      move 16,-12.0
      UserMovement m5,500,1
      flat
      color 1,1,1,1
      texture imgn2
      quadnorm 10.0,10.0*imgnHt/imgnWi 'apply image texture to quad
      texture 1
    popstate
 
'------------------------------- new how to display picked object and print its name ? --------------------- //
'
glLoadIdentity
  PickLabel    500
  'gltranslatef -.5,.35,-1.0
  gltranslatef -.15,-.35,-1.0
  float w,h
  glscalef    .07,.07,.01
  GetWordArea  "picked:",w,h ' "Cookies:",w,h
  if pick
    PutBoxArea  w,h
  elseif picked
    glColor3f    .99,.99,.00
    gprint      "picked:" ''"Cookies: "
    glColor3f    .99,.99,.99
    gprint      picked
  end if
  glPopMatrix
  '
  EndPick
'------------------------------- new how to display picked object and print its name ? --------------------- //


  'static float ang
  'ang+=.5 : if ang>=360 then ang-=360
  end sub 'main

  EndScript


Charles Pegge

#1
Hi Frank,
Toward the end of the original script,  this will print the picked identity number

    'Display info at top
    pushstate
      move 0,-.5
      scale 2
      'display identity of picked objects m1.id  m2.id  m3.id etc
      printl "2D Graphics:    object: " + picked
    popstate

m1 m2 m3 are UserMovement objects. You can have any number of them to move different parts of the scene.

Frank Brübach

Yes thanks .. but I wanted to Print the pickLabel too with Name EG m 500 is my Cookies , m200 IS my butterfly ...

Charles Pegge

If you want to lock say m3 in a fixed position you can specify m3.lock=1

Frank Brübach

Thanks but I dont know how to BE truly.. I can only Display a permanent Text of the objects Like Cookie or butterfly .. the id 100 200 300 to Show is No Problem but my Idea was to click a pic or Text and then the Name of the objects should BE also displayed..
 
  '#compact
  % filename "t.exe"
 'uses RTL64

  % Title "Console Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  uses ConsoleG

  sub main
  ========
   sys id
   move 0, -.0.5
scale 1.125 '2
printl "2D graphics: objects: " + picked  '+ id '' m1.id, m2.id, m3.id...

  if opening then
    CreateTexture imgn,"../../images/Dawn1815.jpg"
  end if
  cls
  pushstate

    pushstate
      UserMovement m1,100,1
      'printl "graphic circle"
      move 5,-6
      color .50,.00,.70,1.0 : fan 5.,000. ,060. ,2.0 'wedge
      color .40,.50,.00,1.0 : fan 5.,060,120,2 'wedge
      color 1,1,0,1
      move .0,.0,.0001
      color .00,.00,.30,.5 : fan 3.,000,360,2 'transp overlay
      thickness 2
      color .90,.20,.00,.5 : arc 5,0,120,1
    popstate

    '
    move 0,0,.0002 'next layer
    '
    'FILE IMAGE
    pushstate
      move 11,-18.0
      UserMovement m2,200,1
      printl "pic"
      flat
      color 1,1,1,1
      texture imgn
      quadnorm 10.0,10.0*imgnHt/imgnWi 'apply image texture to quad
      texture 0
    popstate

    move 0,0,.0002 'next layer

    'GRID
    pushstate
      move 11,-18.0
      UserMovement m3,300,1
      thickness 1
      color 1,0,0,0
      color .0,.5,.7,1
      grid 1.,20,10 'fine grid
      thickness 3
      move .0,.0,.0001
      grid 1.,20,10,5,1 'thick grid with pickable overlay
    popstate

    move 0,0,.0002 'next layer

    pushstate
      move 0,-.5
      scale 2
      printl "2D Graphics"
    popstate

  popstate

  'static float ang
  'ang+=.5 : if ang>=360 then ang-=360
  end sub 'main

  EndScript

Charles Pegge

Do you want the labels to move with the images, or , to appear in a fixed position at the top?

Frank Brübach

#6
I can Display the for example the label m100 simply below the usermovement Block and took printl 'cookie" next line below.. but then the Text is permanent fixed.. on the Image ...

Better would be the label in the top Line with the picked objects + id number say the Name of the objects behind all in one Line  :-)

Thanks!

Charles Pegge

You can use the id (m1.id m2.id etc) to index a string array containing the corresponding text you want to display at the top.

Frank Brübach

Yes but how to Program m1.id ? I tried already but got an Error its a Type Statement or a class? Found nothing in consoleG.inc

Charles Pegge

Yes it's a variable/property. You can read or write to it. Even set a new identity.

Charles Pegge

The properties of a MoveableObject (ConsoleG.inc) you can usefully change:

  class MoveableObject
  ====================
  float  x,y,z    'position
  vector s        'scale
  int    id       'identity for picking
  int    locked   'movement & scaling locked
...

I will add  char name[32] in the next update

Frank Brübach

Hello Charles.. how I can Print the Label AS a String with the picked objects? Do you have Made a Progress with Char Name[32] ? Thanks frank

   ' my half solution
  '#compact
  % filename "t.exe"
 'uses RTL64

  % Title "Console Demo"
 '% Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  uses ConsoleG

  sub main
  ========
  if opening then
    CreateTexture imgn,"../../images/Dawn1815.jpg"
  end if
  cls
  pushstate
   
    pushstate
      UserMovement p1,100,1
     
      move 5,-6
      color .50,.00,.70,1.0 : fan 5.,000. ,060. ,2.0 'wedge
      color .40,.50,.00,1.0 : fan 5.,060,120,2 'wedge
      color 1,1,0,1
      move .0,.0,.0001
      color .00,.00,.30,.5 : fan 3.,000,360,2 'transp overlay
      thickness 2
      color .90,.20,.00,.5 : arc 5,0,120,1
    popstate

    '
    move 0,0,.0002 'next layer
    '
    'FILE IMAGE
    pushstate
      move 11,-18.0
      UserMovement p2,200,1
      flat
      color 1,1,1,1
      texture imgn
      quadnorm 10.0,10.0*imgnHt/imgnWi 'apply image texture to quad
      texture 0
    popstate

    move 0,0,.0002 'next layer

    'GRID
    pushstate
      move 11,-18.0
      UserMovement p3,300,1
      thickness 1
      color 1,0,0,0
      color .0,.5,.7,1
      grid 1.,20,10 'fine grid
      thickness 3
      move .0,.0,.0001
      grid 1.,20,10,5,1 'thick grid with pickable overlay
    popstate

    move 0,0,.0002 'next layer

    'Display info at top
    pushstate
      move 0,-.5
      scale 2
      '----------------------------------------------------------- // how ?
      'display identity of picked objects m1.id  m2.id  m3.id etc
      printl "2D Graphics:    object: " + picked ' ok but without the name of picked object as string output
      '----------------------------------------------------------- // how ?
      ' picked object for example 100 = "graphic circle"
      '
    popstate

  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  ' my idea as solution but doesnt work for different labels 200,300 etcpp
  PickLabel 0
  '
  glPushMatrix
  '
  glLoadIdentity
  PickLabel    100
  gltranslatef -.5,.35,-1.0
  float w,h
  glscalef     .07,.07,.01
  GetWordArea  "graphic circle:",w,h
  if pick
    PutBoxArea   w,h
  elseif picked
    glColor3f    .99,.99,.00
    gprint       "graphic circle: "
    glColor3f    .99,.99,.99
    gprint       picked
  end if
  glPopMatrix
  '
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
  popstate

  'static float ang
  'ang+=.5 : if ang>=360 then ang-=360
  end sub 'main

  EndScript
[\Code]

Charles Pegge

Hi Frank,

I have updated inc\ConsoleG.inc and demos\opengl\consoleG\Graphics2D.o2bas
Attached below.

The .name property is now included


The selected name appears when you point, click and keep the left button down.
The picked name will also appear at the top after the id number.

Frank Brübach

#13
Many thanks Charles.. Now all is running AS I wished with the selected objects and the Name.
You have used a macro for it good Idea. And I  have checked usermovement macro too where you have placed the String .. thx learned a new Thing again :-)

PS: how Long did you have needed for o2 openGL library and where do you have started with? Kronos examples?

Charles Pegge

About 14 years ago. I had some advice from Mike Lobanovsky, and looked at the NeHe examples as well as the Khronos documentation. But my interest in OpenGl goes back to the PowerBasic days. Before OpenGl, I used PovRay ray tracing, and experimented with X3D (VRML).