Results 1 to 7 of 7

Thread: C gl and glu code conversion to thinBasic

  1. #1
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    C gl and glu code conversion to thinBasic

    Inspired by Matthews work and the NeHe lessons and of course Petr's tutorials. I decided tonight to see if I could do a conversion. After some work I did, so am very happy.

    I got the c code and read the tutorial at this site:
    http://www.gmonline.demon.co.uk/cscene/CS5/CS5-03.html

    Here is the code I looked at:
    [code=c]/**********************************************************************/
    /******************************************/
    /* A Very Simple OpenGL Example! */
    /******************************************/

    /* this code just creates a window and draws a rectangle in it */

    #include <windows.h> /* obviously change this to your native library
    if you're compiling under unix */
    #include <gl\gl.h>
    #include <gl\glut.h>

    void init(void);
    void display(void);

    int main (int argc, char **argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInitWindowSize(250, 250);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("My First OpenGL Application");
    init();
    glutDisplayFunc(display);
    glutMainLoop();
    return 0;
    }

    void init(void)
    {
    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);
    }

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glRectf(-5.0, 5.0, 5.0, -5.0);
    glutSwapBuffers();
    }
    /**********************************************************************/[/code]

    Here is the thinBasic conversion I did, woo hoo!!
    [code=thinbasic] '---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)
    end sub [/code]
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,795
    Rep Power
    10

    Re: C gl and glu code conversion to thinBasic

    Hey, seems OK. Good.
    UI module is not needed because you used all new TBGL functions Petr added in order to avoid inclusion of UI module.

    Thanks a lot.
    You proved once again we can go on with thinBasic development. Sometimes we need some pusher If we can do what a C code can do ...
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: C gl and glu code conversion to thinBasic

    It is nice to see how similar but at the same time how much nicer thinBasic code looks than C. Petr did a great job making the opengl module that is for sure!!!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,138
    Rep Power
    733

    Re: C gl and glu code conversion to thinBasic

    Hi kryton,

    nice sample !
    GLUT is also nice, I have played some years ago with that.


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: C gl and glu code conversion to thinBasic

    Petr, nice how you did all of this. I also tried mixing tbgl with gl and glu and it all works great. Thanks!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

  6. #6

    Re: C gl and glu code conversion to thinBasic

    Nice Programme, it reminds me of One of the Example Programmes in the OpenGL Redbook.
    Operating System: Windows 10 Home 64-bit
    CPU: Intel Celeron N4000 CPU @ 1.10GHz
    Memory: 4.00GB RAM
    Graphics: Intel UHD Graphics 600

  7. #7
    thinBasic MVPs kryton9's Avatar
    Join Date
    Nov 2006
    Location
    Naples, Florida & Duluth, Georgia
    Age
    68
    Posts
    3,869
    Rep Power
    404

    Re: C gl and glu code conversion to thinBasic

    Thanks guys. I never was good at doing conversions, so it was a big step for me. Luckilly this example was simple enough to do.
    I couldn't have done it without referring to your guys examples, I had many sources open in thinAir and was switching back and forth trying to see how things should work. So your great examples made it all possible thanks!
    Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
    Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server

Similar Threads

  1. Replies: 1
    Last Post: 11-11-2010, 14:29
  2. base conversion
    By Michael Clease in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 3
    Last Post: 11-11-2007, 23:00

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •