Jump to content

C++ OpenGL calculator

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
maxwkh

maxwkh

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

Does anyone know how to create a calculator using OpenGL?
Need help for my assignment.

If possible can you give me a example on how to code the basic stuff for a calculator. Eg. button and display number in OpenGL.

Thanks.

#2
PythonPower

PythonPower

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 230 posts
Using OpenGL to create a calculator seems rather odd to me but...

Do you have any functions to output text yet? Do you know at least a bit of OpenGL? What type of calculator are you looking to make; one similar to the Windows Calculator in "standard" mode?

In OpenGL, the buttons could be added to some type of container (maybe a array). Each button code be rendered with a quad at an (x, y) coordinate. Clicking anywhere could trigger a search function that checked to see what button(s) were pressed and call those buttons' functions.

What I'm describing here, though, is just a naive callback system.

#3
davidthefat

davidthefat

    Learning Programmer

  • Members
  • PipPipPip
  • 82 posts
IDK bout you, but did you even google OpenGL tutorials? I mean its a rule in every forum before posting a question, google it... the first result has your answer...

#4
maxwkh

maxwkh

    Newbie

  • Members
  • Pip
  • 2 posts
Hi, I know how to display text now, but the problem that I having is I don't know how to move the text to the left when i insert new text. It will just replace or existing one. Any idea? Thanks

#5
PythonPower

PythonPower

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 230 posts

maxwkh said:

Hi, I know how to display text now, but the problem that I having is I don't know how to move the text to the left when i insert new text. It will just replace or existing one. Any idea? Thanks

A little more code would be helpful since I can't do telepathy. ;)

If you have a function that prints text but you can't position it, then you should consider calling glTranslatef before you draw the text - this will move the text about.

Bear in mind that once you have drawn the text you will need to call glTranslatef with the opposite x, y and z values so you don't offset anything else you draw. It's probably simpler to do something like:

glPushMatrix();
glTranslatef(x, y, 0); //Be careful what dimensions you translate in!

//Draw the text

glPopMatrix();

That way, drawing the text won't effect any later rendering since glPushMatrix saves the state and glPopMatrix restores the previous state.