PDA

View Full Version : C gl and glu code conversion to thinBasic (Again)



zak
11-11-2010, 13:22
Hi
this is an archive of a 4 years old subject, so the old goodies will not lost.
while reading about the OpenGl system coordinates here:
http://www.c-sharpcorner.com/UploadFile/jeradus/OpenGLBasics11172005014307AM/OpenGLBasics.aspx
and trying some examples in thinbasic, (i just deleted the "GL." prefix before OpenGL words in C#),
i remembered the kent post in 2007 when he converted a C program to thinbasic, look the thread here:
http://www.thinbasic.com/community/showthread.php?8033-C-gl-and-glu-code-conversion-to-thinBasic
so i found it is usefull to repost the kent example again, since the code are not formatted well during the move from old forum to new forum, i have pertained the square draw in kent post, and added line draw.
by the way i found it is usefull the phrase in the above article:
OpenGL coordinate system is also called a left handed coordinate system because you can make the same coordinate system with your left hand try to figure it out.

PS: kent was happy when he posted his first C to thinbasic opengl example, so forgive me to repost your precious code again, it can serve as a template for the learners of opengl red book c examples, by using thinbasic to try the red book examples semi directly without the hassle of using C compiler.


'---thanks to Petr and Matthew for great examples
Uses "tbgl"
Uses "ui"
#INCLUDE "%app_includepath%\thinbasic_gl.inc"
#INCLUDE "%app_includepath%\thinbasic_glu.inc"


Dim hwnd As DWord

hwnd = TBGL_CreateWindowEx("my first opengl application - esc to exit", 250, 250, 32, 0)
TBGL_ShowWindow
TBGL_GetAsyncKeyState(-1)
While TBGL_IsWindow(hwnd)
TBGL_ClearFrame
init
display
TBGL_DrawFrame
If TBGL_GetWindowKeyState( hwnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow

Sub init()
glclearcolor(0.0, 0.0, 0.0, 0.0)
glcolor3f(0.0, 0.0, 1.0)
glmatrixmode(%gl_projection)
glloadidentity()
glortho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0)
End Sub

Sub display()
glclear(%gl_color_buffer_bit)
glrectf(-5.0, 5.0, 5.0, -5.0)
glBegin(%GL_LINES)
glColor3f(0.0,1.0,0.0)
glVertex3f(-9.0, 9.0, 0.0)
glVertex3f(9.0, -9.0, 0.0)
glEnd()
End Sub

Petr Schreiber
11-11-2010, 14:29
Thanks Zak,

I am sure many will find this helpful - just one thing:


TBGL_GetAsyncKeyState(-1)


... is still valid, yet cryptic syntax from early times, better to use this instead:


TBGL_ResetKeyState()



Thanks,
Petr