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.
C++ OpenGL calculator
Started by maxwkh, Apr 08 2009 03:28 AM
4 replies to this topic
#1
Posted 08 April 2009 - 03:28 AM
|
|
|
#2
Posted 08 April 2009 - 04:20 AM
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.
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
Posted 08 April 2009 - 05:19 PM
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
Posted 08 April 2009 - 10:06 PM
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
Posted 10 April 2009 - 01:48 AM
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.


Sign In
Create Account

Back to top









