You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Waltersmind's - OpenGL Triangle Demo
02-04-2015, 08:00 AM
Post: #1
 (Print Post)
Waltersmind's - OpenGL Triangle Demo
After seeing some interest about OpenGL in QB64 on QB64.net, I decided to try my hand at it. I took a sample demo that UnSeenMachine created, with some help from Steve McNeil, and studied it. Then I modified it to draw many triangles.

Here is a screenshot:

   

Here is the code to my first OpenGL demo in QB64:

Code Snippet: [Select]
TYPE GL_Triangle
    ColorPointA_Red AS _UNSIGNED _BYTE
    ColorPointA_Green AS _UNSIGNED _BYTE
    ColorPointA_Blue AS _UNSIGNED _BYTE
    ColorPointA_Alpha AS _UNSIGNED _BYTE
    ColorPointB_Red AS _UNSIGNED _BYTE
    ColorPointB_Green AS _UNSIGNED _BYTE
    ColorPointB_Blue AS _UNSIGNED _BYTE
    ColorPointB_Alpha AS _UNSIGNED _BYTE
    ColorPointC_Red AS _UNSIGNED _BYTE
    ColorPointC_Green AS _UNSIGNED _BYTE
    ColorPointC_Blue AS _UNSIGNED _BYTE
    ColorPointC_Alpha AS _UNSIGNED _BYTE
    X AS INTEGER
    Y AS INTEGER
    Z AS INTEGER
    RotationX AS _FLOAT
    RotationY AS _FLOAT
    RotationZ AS _FLOAT
    RotationXInc AS _FLOAT
    RotationYInc AS _FLOAT
    RotationZInc AS _FLOAT
    PointA_X AS _FLOAT
    PointA_Y AS _FLOAT
    PointA_Z AS _FLOAT
    PointB_X AS _FLOAT
    PointB_Y AS _FLOAT
    PointB_Z AS _FLOAT
    PointC_X AS _FLOAT
    PointC_Y AS _FLOAT
    PointC_Z AS _FLOAT
END TYPE

DIM MainScreen AS LONG
DIM SHARED ColorPoint AS DOUBLE
DIM SHARED FOV AS DOUBLE
DIM SHARED AspectRatio AS DOUBLE
DIM SHARED Near AS DOUBLE
DIM SHARED Far AS DOUBLE

DIM NumberOfTriangles AS _UNSIGNED LONG

REDIM SHARED Triangles(-1) AS GL_Triangle

CONST ScreenWidth = 800
CONST ScreenHeight = 600
NumberOfTriangles = 1000

ColorPoint = 1 / 255
FOV = 90
AspectRatio = ScreenWidth / ScreenHeight
Near = 1
Far = 20

REDIM SHARED Triangles(NumberOfTriangles - 1) AS GL_Triangle

MainScreen = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)

SCREEN MainScreen


' *** Let's define the all the triangles we will be drawing

FOR i = 0 TO UBOUND(triangles)

    Triangles(i).ColorPointA_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).X = RND * 10 - 5 'AS INTEGER
    Triangles(i).Y = RND * 8 - 4 'AS INTEGER
    Triangles(i).Z = INT(RND * 6) - 10 '-5  'AS INTEGER
    Triangles(i).RotationX = RND * 360 'AS _FLOAT
    Triangles(i).RotationY = RND * 360 'AS _FLOAT
    Triangles(i).RotationZ = RND * 360 'AS _FLOAT
    Triangles(i).RotationXInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationYInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationZInc = RND * 2 'AS _FLOAT
    Triangles(i).PointA_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Z = RND * 2 - 1 'AS _FLOAT


NEXT

DO
    _LIMIT 60
    _DISPLAY

LOOP WHILE INKEY$ = ""
SYSTEM



SUB _GL

BG_Red = ColorPoint * 2
BG_Green = ColorPoint * 95
BG_Blue = ColorPoint * 193
BG_Alpha = 1

_glClearColor BG_Red, BG_Green, BG_Blue, BG_Alpha
_glClearDepth 1
_glLoadIdentity
_glMatrixMode _GL_PROJECTION
_gluPerspective FOV, AspectRatio, Near, Far
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
_glViewport 0, 0, ScreenWidth, ScreenHeight

_glClear _GL_COLOR_BUFFER_BIT

FOR i = 0 TO UBOUND(triangles)


    _glLoadIdentity
    _glTranslatef Triangles(i).X, Triangles(i).Y, Triangles(i).Z

    _glRotatef Triangles(i).RotationX, 1, 0, 0
    _glRotatef Triangles(i).RotationY, 0, 1, 0
    _glRotatef Triangles(i).RotationZ, 0, 0, 1

    _glBegin _GL_TRIANGLES

    _glColor3ub Triangles(i).ColorPointA_Red, Triangles(i).ColorPointA_Green, Triangles(i).ColorPointA_Blue ', Triangles(i).ColorPointA_Alpha
    _glVertex3f Triangles(i).PointA_X, Triangles(i).PointA_Y, Triangles(i).PointA_Z

    _glColor3ub Triangles(i).ColorPointB_Red, Triangles(i).ColorPointB_Green, Triangles(i).ColorPointB_Blue ', Triangles(i).ColorPointB_Alpha
    _glVertex3f Triangles(i).PointB_X, Triangles(i).PointB_Y, Triangles(i).PointB_Z

    _glColor3ub Triangles(i).ColorPointC_Red, Triangles(i).ColorPointC_Green, Triangles(i).ColorPointC_Blue ', Triangles(i).ColorPointC_Alpha
    _glVertex3f Triangles(i).PointC_X, Triangles(i).PointC_Y, Triangles(i).PointC_Z

    _glEnd

    Triangles(i).RotationX = Triangles(i).RotationX + Triangles(i).RotationXInc: IF Triangles(i).RotationX > 360 THEN Triangles(i).RotationX = Triangles(i).RotationX - 360
    Triangles(i).RotationY = Triangles(i).RotationY + Triangles(i).RotationYInc: IF Triangles(i).RotationY > 360 THEN Triangles(i).RotationY = Triangles(i).RotationY - 360
    Triangles(i).RotationZ = Triangles(i).RotationZ + Triangles(i).RotationZInc: IF Triangles(i).RotationZ > 360 THEN Triangles(i).RotationZ = Triangles(i).RotationZ - 360


NEXT

END SUB

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
The following 1 user Likes Waltersmind's post:
KingAshish
02-05-2015, 05:19 PM
Post: #2
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
Here is the same demo, but with all the triangles having transparency.

Here is a screenshot of the demo:

   


Code Snippet: [Select]
TYPE GL_Triangle
    ColorPointA_Red AS _UNSIGNED _BYTE
    ColorPointA_Green AS _UNSIGNED _BYTE
    ColorPointA_Blue AS _UNSIGNED _BYTE
    ColorPointA_Alpha AS _UNSIGNED _BYTE
    ColorPointB_Red AS _UNSIGNED _BYTE
    ColorPointB_Green AS _UNSIGNED _BYTE
    ColorPointB_Blue AS _UNSIGNED _BYTE
    ColorPointB_Alpha AS _UNSIGNED _BYTE
    ColorPointC_Red AS _UNSIGNED _BYTE
    ColorPointC_Green AS _UNSIGNED _BYTE
    ColorPointC_Blue AS _UNSIGNED _BYTE
    ColorPointC_Alpha AS _UNSIGNED _BYTE
    X AS INTEGER
    Y AS INTEGER
    Z AS INTEGER
    RotationX AS _FLOAT
    RotationY AS _FLOAT
    RotationZ AS _FLOAT
    RotationXInc AS _FLOAT
    RotationYInc AS _FLOAT
    RotationZInc AS _FLOAT
    PointA_X AS _FLOAT
    PointA_Y AS _FLOAT
    PointA_Z AS _FLOAT
    PointB_X AS _FLOAT
    PointB_Y AS _FLOAT
    PointB_Z AS _FLOAT
    PointC_X AS _FLOAT
    PointC_Y AS _FLOAT
    PointC_Z AS _FLOAT
END TYPE

DIM MainScreen AS LONG
DIM SHARED ColorPoint AS DOUBLE
DIM SHARED FOV AS DOUBLE
DIM SHARED AspectRatio AS DOUBLE
DIM SHARED Near AS DOUBLE
DIM SHARED Far AS DOUBLE

DIM NumberOfTriangles AS _UNSIGNED LONG

REDIM SHARED Triangles(-1) AS GL_Triangle

CONST ScreenWidth = 800
CONST ScreenHeight = 600
NumberOfTriangles = 1000

ColorPoint = 1 / 255
FOV = 90
AspectRatio = ScreenWidth / ScreenHeight
Near = 1
Far = 20

REDIM SHARED Triangles(NumberOfTriangles - 1) AS GL_Triangle

MainScreen = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)

SCREEN MainScreen


' *** Let's define the all the triangles we will be drawing

FOR i = 0 TO UBOUND(triangles)

    Triangles(i).ColorPointA_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Alpha = INT(RND * 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).X = RND * 10 - 5 'AS INTEGER
    Triangles(i).Y = RND * 8 - 4 'AS INTEGER
    Triangles(i).Z = INT(RND * 6) - 10 '-5  'AS INTEGER
    Triangles(i).RotationX = RND * 360 'AS _FLOAT
    Triangles(i).RotationY = RND * 360 'AS _FLOAT
    Triangles(i).RotationZ = RND * 360 'AS _FLOAT
    Triangles(i).RotationXInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationYInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationZInc = RND * 2 'AS _FLOAT
    Triangles(i).PointA_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Z = RND * 2 - 1 'AS _FLOAT


NEXT

DO
    _LIMIT 60
    _DISPLAY

LOOP WHILE INKEY$ = ""
SYSTEM



SUB _GL

BG_Red = ColorPoint * 2
BG_Green = ColorPoint * 95
BG_Blue = ColorPoint * 193
BG_Alpha = 1

_glClearColor BG_Red, BG_Green, BG_Blue, BG_Alpha
_glClearDepth 1
_glLoadIdentity
_glMatrixMode _GL_PROJECTION
_gluPerspective FOV, AspectRatio, Near, Far
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
_glViewport 0, 0, ScreenWidth, ScreenHeight

_glClear _GL_COLOR_BUFFER_BIT

' *** TURN ON TRANSPARENCY
_glEnable (_GL_BLEND)


FOR i = 0 TO UBOUND(triangles)


    _glLoadIdentity
    _glTranslatef Triangles(i).X, Triangles(i).Y, Triangles(i).Z

    _glRotatef Triangles(i).RotationX, 1, 0, 0
    _glRotatef Triangles(i).RotationY, 0, 1, 0
    _glRotatef Triangles(i).RotationZ, 0, 0, 1

    _glBegin _GL_TRIANGLES

    _glColor4ub Triangles(i).ColorPointA_Red, Triangles(i).ColorPointA_Green, Triangles(i).ColorPointA_Blue, Triangles(i).ColorPointA_Alpha
    _glVertex3f Triangles(i).PointA_X, Triangles(i).PointA_Y, Triangles(i).PointA_Z

    _glColor4ub Triangles(i).ColorPointB_Red, Triangles(i).ColorPointB_Green, Triangles(i).ColorPointB_Blue, Triangles(i).ColorPointB_Alpha
    _glVertex3f Triangles(i).PointB_X, Triangles(i).PointB_Y, Triangles(i).PointB_Z

    _glColor4ub Triangles(i).ColorPointC_Red, Triangles(i).ColorPointC_Green, Triangles(i).ColorPointC_Blue, Triangles(i).ColorPointC_Alpha
    _glVertex3f Triangles(i).PointC_X, Triangles(i).PointC_Y, Triangles(i).PointC_Z

    _glEnd

    Triangles(i).RotationX = Triangles(i).RotationX + Triangles(i).RotationXInc: IF Triangles(i).RotationX > 360 THEN Triangles(i).RotationX = Triangles(i).RotationX - 360
    Triangles(i).RotationY = Triangles(i).RotationY + Triangles(i).RotationYInc: IF Triangles(i).RotationY > 360 THEN Triangles(i).RotationY = Triangles(i).RotationY - 360
    Triangles(i).RotationZ = Triangles(i).RotationZ + Triangles(i).RotationZInc: IF Triangles(i).RotationZ > 360 THEN Triangles(i).RotationZ = Triangles(i).RotationZ - 360


NEXT

END SUB

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
The following 1 user Likes Waltersmind's post:
KingAshish
02-05-2015, 07:10 PM
Post: #3
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
This OpenGL triangle demo is a little different, and if you have epilepsy, you may not want to view this demo. All of the RGBA channels are constantly rotated which causes the triangles to twinkle and appear to be spinning out-of-control rainbow glass.

Here is a screenshot (which doesn't do it justice):

   

Here is the code:

Code Snippet: [Select]
TYPE GL_Triangle
    ColorPointA_Red AS _UNSIGNED _BYTE
    ColorPointA_Green AS _UNSIGNED _BYTE
    ColorPointA_Blue AS _UNSIGNED _BYTE
    ColorPointA_Alpha AS _UNSIGNED _BYTE
    ColorPointB_Red AS _UNSIGNED _BYTE
    ColorPointB_Green AS _UNSIGNED _BYTE
    ColorPointB_Blue AS _UNSIGNED _BYTE
    ColorPointB_Alpha AS _UNSIGNED _BYTE
    ColorPointC_Red AS _UNSIGNED _BYTE
    ColorPointC_Green AS _UNSIGNED _BYTE
    ColorPointC_Blue AS _UNSIGNED _BYTE
    ColorPointC_Alpha AS _UNSIGNED _BYTE
    X AS INTEGER
    Y AS INTEGER
    Z AS INTEGER
    RotationX AS _FLOAT
    RotationY AS _FLOAT
    RotationZ AS _FLOAT
    RotationXInc AS _FLOAT
    RotationYInc AS _FLOAT
    RotationZInc AS _FLOAT
    PointA_X AS _FLOAT
    PointA_Y AS _FLOAT
    PointA_Z AS _FLOAT
    PointB_X AS _FLOAT
    PointB_Y AS _FLOAT
    PointB_Z AS _FLOAT
    PointC_X AS _FLOAT
    PointC_Y AS _FLOAT
    PointC_Z AS _FLOAT
END TYPE

DIM MainScreen AS LONG
DIM SHARED ColorPoint AS DOUBLE
DIM SHARED FOV AS DOUBLE
DIM SHARED AspectRatio AS DOUBLE
DIM SHARED Near AS DOUBLE
DIM SHARED Far AS DOUBLE

DIM NumberOfTriangles AS _UNSIGNED LONG

REDIM SHARED Triangles(-1) AS GL_Triangle

CONST ScreenWidth = 800
CONST ScreenHeight = 600
NumberOfTriangles = 1000

ColorPoint = 1 / 255
FOV = 90
AspectRatio = ScreenWidth / ScreenHeight
Near = 1
Far = 100

REDIM SHARED Triangles(NumberOfTriangles - 1) AS GL_Triangle

MainScreen = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)

SCREEN MainScreen


' *** Let's define the all the triangles we will be drawing

FOR i = 0 TO UBOUND(triangles)

    Triangles(i).ColorPointA_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Alpha = INT(RND * 256) '128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Alpha = INT(RND * 256) '128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Alpha = INT(RND * 256) ' 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).X = RND * 10 - 5 'AS INTEGER
    Triangles(i).Y = RND * 8 - 4 'AS INTEGER
    Triangles(i).Z = INT(RND * 6) - 10 '-5  'AS INTEGER
    Triangles(i).RotationX = RND * 360 'AS _FLOAT
    Triangles(i).RotationY = RND * 360 'AS _FLOAT
    Triangles(i).RotationZ = RND * 360 'AS _FLOAT
    Triangles(i).RotationXInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationYInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationZInc = RND * 2 'AS _FLOAT
    Triangles(i).PointA_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Z = RND * 2 - 1 'AS _FLOAT


NEXT

DO
    _LIMIT 60
    _DISPLAY

LOOP WHILE INKEY$ = ""
SYSTEM



SUB _GL

BG_Red = ColorPoint * 2
BG_Green = ColorPoint * 95
BG_Blue = ColorPoint * 193
BG_Alpha = 1

_glClearColor BG_Red, BG_Green, BG_Blue, BG_Alpha
_glClearDepth 1
_glLoadIdentity
_glMatrixMode _GL_PROJECTION
_gluPerspective FOV, AspectRatio, Near, Far
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
_glViewport 0, 0, ScreenWidth, ScreenHeight

_glClear _GL_COLOR_BUFFER_BIT

' *** TURN ON TRANSPARENCY
_glEnable (_GL_BLEND)


FOR i = 0 TO UBOUND(triangles)


    _glLoadIdentity
    _glTranslatef Triangles(i).X, Triangles(i).Y, Triangles(i).Z

    _glRotatef Triangles(i).RotationX, 1, 0, 0
    _glRotatef Triangles(i).RotationY, 0, 1, 0
    _glRotatef Triangles(i).RotationZ, 0, 0, 1

    _glBegin _GL_TRIANGLES

    _glColor4ub Triangles(i).ColorPointA_Red, Triangles(i).ColorPointA_Green, Triangles(i).ColorPointA_Blue, Triangles(i).ColorPointA_Alpha
    _glVertex3f Triangles(i).PointA_X, Triangles(i).PointA_Y, Triangles(i).PointA_Z

    _glColor4ub Triangles(i).ColorPointB_Red, Triangles(i).ColorPointB_Green, Triangles(i).ColorPointB_Blue, Triangles(i).ColorPointB_Alpha
    _glVertex3f Triangles(i).PointB_X, Triangles(i).PointB_Y, Triangles(i).PointB_Z

    _glColor4ub Triangles(i).ColorPointC_Red, Triangles(i).ColorPointC_Green, Triangles(i).ColorPointC_Blue, Triangles(i).ColorPointC_Alpha
    _glVertex3f Triangles(i).PointC_X, Triangles(i).PointC_Y, Triangles(i).PointC_Z

    _glEnd

    Triangles(i).RotationX = Triangles(i).RotationX + Triangles(i).RotationXInc: IF Triangles(i).RotationX > 360 THEN Triangles(i).RotationX = Triangles(i).RotationX - 360
    Triangles(i).RotationY = Triangles(i).RotationY + Triangles(i).RotationYInc: IF Triangles(i).RotationY > 360 THEN Triangles(i).RotationY = Triangles(i).RotationY - 360
    Triangles(i).RotationZ = Triangles(i).RotationZ + Triangles(i).RotationZInc: IF Triangles(i).RotationZ > 360 THEN Triangles(i).RotationZ = Triangles(i).RotationZ - 360

    Triangles(i).ColorPointA_Red = Triangles(i).ColorPointA_Red + 1: IF Triangles(i).ColorPointA_Red > 255 THEN Triangles(i).ColorPointA_Red = Triangles(i).ColorPointA_Red - 255
    Triangles(i).ColorPointA_Green = Triangles(i).ColorPointA_Green + 1: IF Triangles(i).ColorPointA_Green > 255 THEN Triangles(i).ColorPointA_Green = Triangles(i).ColorPointA_Green - 255
    Triangles(i).ColorPointA_Blue = Triangles(i).ColorPointA_Blue + 1: IF Triangles(i).ColorPointA_Blue > 255 THEN Triangles(i).ColorPointA_Blue = Triangles(i).ColorPointA_Blue - 255
    Triangles(i).ColorPointA_Alpha = Triangles(i).ColorPointA_Alpha + 15: IF Triangles(i).ColorPointA_Alpha > 255 THEN Triangles(i).ColorPointA_Alpha = Triangles(i).ColorPointA_Alpha - 255

    Triangles(i).ColorPointB_Red = Triangles(i).ColorPointB_Red + 1: IF Triangles(i).ColorPointB_Red > 255 THEN Triangles(i).ColorPointB_Red = Triangles(i).ColorPointB_Red - 255
    Triangles(i).ColorPointB_Green = Triangles(i).ColorPointB_Green + 1: IF Triangles(i).ColorPointB_Green > 255 THEN Triangles(i).ColorPointB_Green = Triangles(i).ColorPointB_Green - 255
    Triangles(i).ColorPointB_Blue = Triangles(i).ColorPointB_Blue + 1: IF Triangles(i).ColorPointB_Blue > 255 THEN Triangles(i).ColorPointB_Blue = Triangles(i).ColorPointB_Blue - 255
    Triangles(i).ColorPointB_Alpha = Triangles(i).ColorPointB_Alpha + 15: IF Triangles(i).ColorPointB_Alpha > 255 THEN Triangles(i).ColorPointB_Alpha = Triangles(i).ColorPointB_Alpha - 255

    Triangles(i).ColorPointC_Red = Triangles(i).ColorPointC_Red + 1: IF Triangles(i).ColorPointC_Red > 255 THEN Triangles(i).ColorPointC_Red = Triangles(i).ColorPointC_Red - 255
    Triangles(i).ColorPointC_Green = Triangles(i).ColorPointC_Green + 1: IF Triangles(i).ColorPointC_Green > 255 THEN Triangles(i).ColorPointC_Green = Triangles(i).ColorPointC_Green - 255
    Triangles(i).ColorPointC_Blue = Triangles(i).ColorPointC_Blue + 1: IF Triangles(i).ColorPointC_Blue > 255 THEN Triangles(i).ColorPointC_Blue = Triangles(i).ColorPointC_Blue - 255
    Triangles(i).ColorPointC_Alpha = Triangles(i).ColorPointC_Alpha + 15: IF Triangles(i).ColorPointC_Alpha > 255 THEN Triangles(i).ColorPointC_Alpha = Triangles(i).ColorPointC_Alpha - 255


NEXT

END SUB


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
The following 1 user Likes Waltersmind's post:
KingAshish
02-05-2015, 09:32 PM
Post: #4
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
This is the same demo as above except this one has outlines around the triangles.

Here is a screenshot:

   


Here is the code:

Code Snippet: [Select]
TYPE GL_Triangle
    ColorPointA_Red AS _UNSIGNED _BYTE
    ColorPointA_Green AS _UNSIGNED _BYTE
    ColorPointA_Blue AS _UNSIGNED _BYTE
    ColorPointA_Alpha AS _UNSIGNED _BYTE
    ColorPointB_Red AS _UNSIGNED _BYTE
    ColorPointB_Green AS _UNSIGNED _BYTE
    ColorPointB_Blue AS _UNSIGNED _BYTE
    ColorPointB_Alpha AS _UNSIGNED _BYTE
    ColorPointC_Red AS _UNSIGNED _BYTE
    ColorPointC_Green AS _UNSIGNED _BYTE
    ColorPointC_Blue AS _UNSIGNED _BYTE
    ColorPointC_Alpha AS _UNSIGNED _BYTE
    X AS INTEGER
    Y AS INTEGER
    Z AS INTEGER
    RotationX AS _FLOAT
    RotationY AS _FLOAT
    RotationZ AS _FLOAT
    RotationXInc AS _FLOAT
    RotationYInc AS _FLOAT
    RotationZInc AS _FLOAT
    PointA_X AS _FLOAT
    PointA_Y AS _FLOAT
    PointA_Z AS _FLOAT
    PointB_X AS _FLOAT
    PointB_Y AS _FLOAT
    PointB_Z AS _FLOAT
    PointC_X AS _FLOAT
    PointC_Y AS _FLOAT
    PointC_Z AS _FLOAT
END TYPE

DIM MainScreen AS LONG
DIM SHARED ColorPoint AS DOUBLE
DIM SHARED FOV AS DOUBLE
DIM SHARED AspectRatio AS DOUBLE
DIM SHARED Near AS DOUBLE
DIM SHARED Far AS DOUBLE

DIM NumberOfTriangles AS _UNSIGNED LONG

REDIM SHARED Triangles(-1) AS GL_Triangle

CONST ScreenWidth = 800
CONST ScreenHeight = 600
NumberOfTriangles = 350

ColorPoint = 1 / 255
FOV = 90
AspectRatio = ScreenWidth / ScreenHeight
Near = 1
Far = 100

REDIM SHARED Triangles(NumberOfTriangles - 1) AS GL_Triangle

MainScreen = _NEWIMAGE(ScreenWidth, ScreenHeight, 32)

SCREEN MainScreen


' *** Let's define the all the triangles we will be drawing

FOR i = 0 TO UBOUND(triangles)

    Triangles(i).ColorPointA_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointA_Alpha = INT(RND * 256) '128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointB_Alpha = INT(RND * 256) '128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Red = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Green = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Blue = INT(RND * 256) 'AS _UNSIGNED _BYTE
    Triangles(i).ColorPointC_Alpha = INT(RND * 256) ' 128) + 64 'AS _UNSIGNED _BYTE
    Triangles(i).X = RND * 10 - 5 'AS INTEGER
    Triangles(i).Y = RND * 8 - 4 'AS INTEGER
    Triangles(i).Z = INT(RND * 6) - 10 '-5  'AS INTEGER
    Triangles(i).RotationX = RND * 360 'AS _FLOAT
    Triangles(i).RotationY = RND * 360 'AS _FLOAT
    Triangles(i).RotationZ = RND * 360 'AS _FLOAT
    Triangles(i).RotationXInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationYInc = RND * 2 'AS _FLOAT
    Triangles(i).RotationZInc = RND * 2 'AS _FLOAT
    Triangles(i).PointA_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointA_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointB_Z = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_X = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Y = RND * 2 - 1 'AS _FLOAT
    Triangles(i).PointC_Z = RND * 2 - 1 'AS _FLOAT


NEXT

DO
    _LIMIT 60
    _DISPLAY

LOOP WHILE INKEY$ = ""
SYSTEM



SUB _GL

BG_Red = ColorPoint * 2
BG_Green = ColorPoint * 95
BG_Blue = ColorPoint * 193
BG_Alpha = 1

_glClearColor BG_Red, BG_Green, BG_Blue, BG_Alpha
_glClearDepth 1
_glLoadIdentity
_glMatrixMode _GL_PROJECTION
_gluPerspective FOV, AspectRatio, Near, Far
_glMatrixMode _GL_MODELVIEW
_glLoadIdentity
_glViewport 0, 0, ScreenWidth, ScreenHeight

_glClear _GL_COLOR_BUFFER_BIT

' *** TURN ON TRANSPARENCY
_glEnable (_GL_BLEND)
_glEnable (_GL_LINE_SMOOTH)


FOR i = 0 TO UBOUND(triangles)


    _glLoadIdentity
    _glTranslatef Triangles(i).X, Triangles(i).Y, Triangles(i).Z

    _glRotatef Triangles(i).RotationX, 1, 0, 0
    _glRotatef Triangles(i).RotationY, 0, 1, 0
    _glRotatef Triangles(i).RotationZ, 0, 0, 1

    _glBegin _GL_TRIANGLES

    _glColor4ub Triangles(i).ColorPointA_Red, Triangles(i).ColorPointA_Green, Triangles(i).ColorPointA_Blue, Triangles(i).ColorPointA_Alpha
    _glVertex3f Triangles(i).PointA_X, Triangles(i).PointA_Y, Triangles(i).PointA_Z

    _glColor4ub Triangles(i).ColorPointB_Red, Triangles(i).ColorPointB_Green, Triangles(i).ColorPointB_Blue, Triangles(i).ColorPointB_Alpha
    _glVertex3f Triangles(i).PointB_X, Triangles(i).PointB_Y, Triangles(i).PointB_Z

    _glColor4ub Triangles(i).ColorPointC_Red, Triangles(i).ColorPointC_Green, Triangles(i).ColorPointC_Blue, Triangles(i).ColorPointC_Alpha
    _glVertex3f Triangles(i).PointC_X, Triangles(i).PointC_Y, Triangles(i).PointC_Z

    _glEnd


    _glLoadIdentity
    _glTranslatef Triangles(i).X, Triangles(i).Y, Triangles(i).Z

    _glRotatef Triangles(i).RotationX, 1, 0, 0
    _glRotatef Triangles(i).RotationY, 0, 1, 0
    _glRotatef Triangles(i).RotationZ, 0, 0, 1


    _glLineWidth (1.5)

    _glBegin _GL_LINE_LOOP

    _glColor4ub Triangles(i).ColorPointA_Red, Triangles(i).ColorPointA_Green, Triangles(i).ColorPointA_Blue, 180 'Triangles(i).ColorPointA_Alpha
    _glVertex3f Triangles(i).PointA_X, Triangles(i).PointA_Y, Triangles(i).PointA_Z

    _glColor4ub Triangles(i).ColorPointB_Red, Triangles(i).ColorPointB_Green, Triangles(i).ColorPointB_Blue, 180 'Triangles(i).ColorPointB_Alpha
    _glVertex3f Triangles(i).PointB_X, Triangles(i).PointB_Y, Triangles(i).PointB_Z

    _glColor4ub Triangles(i).ColorPointC_Red, Triangles(i).ColorPointC_Green, Triangles(i).ColorPointC_Blue, 180 'Triangles(i).ColorPointC_Alpha
    _glVertex3f Triangles(i).PointC_X, Triangles(i).PointC_Y, Triangles(i).PointC_Z

    _glEnd


    Triangles(i).RotationX = Triangles(i).RotationX + Triangles(i).RotationXInc: IF Triangles(i).RotationX > 360 THEN Triangles(i).RotationX = Triangles(i).RotationX - 360
    Triangles(i).RotationY = Triangles(i).RotationY + Triangles(i).RotationYInc: IF Triangles(i).RotationY > 360 THEN Triangles(i).RotationY = Triangles(i).RotationY - 360
    Triangles(i).RotationZ = Triangles(i).RotationZ + Triangles(i).RotationZInc: IF Triangles(i).RotationZ > 360 THEN Triangles(i).RotationZ = Triangles(i).RotationZ - 360

    Triangles(i).ColorPointA_Red = Triangles(i).ColorPointA_Red + 1: IF Triangles(i).ColorPointA_Red > 255 THEN Triangles(i).ColorPointA_Red = Triangles(i).ColorPointA_Red - 255
    Triangles(i).ColorPointA_Green = Triangles(i).ColorPointA_Green + 1: IF Triangles(i).ColorPointA_Green > 255 THEN Triangles(i).ColorPointA_Green = Triangles(i).ColorPointA_Green - 255
    Triangles(i).ColorPointA_Blue = Triangles(i).ColorPointA_Blue + 1: IF Triangles(i).ColorPointA_Blue > 255 THEN Triangles(i).ColorPointA_Blue = Triangles(i).ColorPointA_Blue - 255
    Triangles(i).ColorPointA_Alpha = Triangles(i).ColorPointA_Alpha + 15: IF Triangles(i).ColorPointA_Alpha > 255 THEN Triangles(i).ColorPointA_Alpha = Triangles(i).ColorPointA_Alpha - 255

    Triangles(i).ColorPointB_Red = Triangles(i).ColorPointB_Red + 1: IF Triangles(i).ColorPointB_Red > 255 THEN Triangles(i).ColorPointB_Red = Triangles(i).ColorPointB_Red - 255
    Triangles(i).ColorPointB_Green = Triangles(i).ColorPointB_Green + 1: IF Triangles(i).ColorPointB_Green > 255 THEN Triangles(i).ColorPointB_Green = Triangles(i).ColorPointB_Green - 255
    Triangles(i).ColorPointB_Blue = Triangles(i).ColorPointB_Blue + 1: IF Triangles(i).ColorPointB_Blue > 255 THEN Triangles(i).ColorPointB_Blue = Triangles(i).ColorPointB_Blue - 255
    Triangles(i).ColorPointB_Alpha = Triangles(i).ColorPointB_Alpha + 15: IF Triangles(i).ColorPointB_Alpha > 255 THEN Triangles(i).ColorPointB_Alpha = Triangles(i).ColorPointB_Alpha - 255

    Triangles(i).ColorPointC_Red = Triangles(i).ColorPointC_Red + 1: IF Triangles(i).ColorPointC_Red > 255 THEN Triangles(i).ColorPointC_Red = Triangles(i).ColorPointC_Red - 255
    Triangles(i).ColorPointC_Green = Triangles(i).ColorPointC_Green + 1: IF Triangles(i).ColorPointC_Green > 255 THEN Triangles(i).ColorPointC_Green = Triangles(i).ColorPointC_Green - 255
    Triangles(i).ColorPointC_Blue = Triangles(i).ColorPointC_Blue + 1: IF Triangles(i).ColorPointC_Blue > 255 THEN Triangles(i).ColorPointC_Blue = Triangles(i).ColorPointC_Blue - 255
    Triangles(i).ColorPointC_Alpha = Triangles(i).ColorPointC_Alpha + 15: IF Triangles(i).ColorPointC_Alpha > 255 THEN Triangles(i).ColorPointC_Alpha = Triangles(i).ColorPointC_Alpha - 255

    LINE (0, 0)-(800, 600), _RGB(255, 255, 0)


NEXT

END SUB

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
The following 1 user Likes Waltersmind's post:
KingAshish
08-20-2017, 08:18 AM
Post: #5
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
Hey KingAshish! Did you catch my link from the QB64.net? This is awesome stuff!

B += _
Find all posts by this user
Like Post
08-20-2017, 01:19 PM
Post: #6
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
@bplus

These little demos were my attempt at creating something with OpenGL in QB64. This was me trying to learn.

I don't think I ever saw your link over at QB64.net that pointed to this thread, but thank you for the link and the excitement in my work.

Personally, OpenGL is still relatively new to me, but my experiences in hardware acceleration stems from using DirectX for Windows. I use to create a lot of 2D demos years ago in Visual Basic 6.0 that used DirectX 6, 7, and 9, but sadly I lost all of them over time. But, those old demos were the inspiration for my "UFO In Space with Fading Tail ver 2.0" demo located at http://www.thejoyfulprogrammer.com/qb64/...hp?tid=523 and my "UFO In Space with Fading Tail ver 3.0" located at http://www.thejoyfulprogrammer.com/qb64/...hp?tid=524.


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post
08-20-2017, 02:12 PM (This post was last modified: 08-20-2017 02:15 PM by bplus.)
Post: #7
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
Hi Walter, 

Yes! KingAshish found this on Coloring Triangles this morning that I had missed until this morning.
http://www.thejoyfulprogrammer.com/qb64/...5359009958

My comment linking from QB64.net was made under beginner's help where I was inquiring about filled triangles and/or filled poly's.
So I was even more surprised and impressed by the link above about coloring this morning.

B += _
Find all posts by this user
Like Post
08-21-2017, 06:43 AM
Post: #8
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
Hi blus! Smile
No, I've not catch your link from QB64.net. I've already seen this cool demo before a couple of months. Wink
Find all posts by this user
Like Post
08-21-2017, 08:19 PM
Post: #9
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
That is fantastic Walter. Great work. I sure do have a lot to still learn.

Donald
Find all posts by this user
Like Post
08-22-2017, 12:21 AM
Post: #10
 (Print Post)
RE: Waltersmind's - OpenGL Triangle Demo
Donald,

We all will always have new things to learn until the day we can not lean no more. After 30+ years, I am still striving for perfection and professionalism in my work, both in the crafting of the code, and the things I learn to make with those magical words.

This forum is here to help teach people things they never knew, and that goes for myself as well.

I am in the process of moving (well, will be shortly), but once I get settled in and can think clearly, I want to spend more time creating ways of teaching people knew things and ideas instead of just sharing code. I want to create a section (which one is already made, but hidden from the rest of you) on this forum where I will write articles on the fundamental details on how things work instead of writing code to show how I would use those fundamental ideas to create the cool demos I make.

Knowledge is the understanding of the fundamentals of how things work. When you have that knowledge, or at least a good concept of it, then you can take your tools (programming languages) and craft that understanding and knowledge into a living demo or application.

To me, coding is the means to bringing my ideas to life were they can be used as they are intended. This means that if the living idea is a game, then it is meant to entertain, teach, educate, rack your brain, and everything else related to what games do. This goes for anything else that is brought to digital life through the language of computer code.

If you would like to know how to do something, please ask. I will be happy to try to help share the knowledge.


Walter Whitman
The Joyful Programmer

My goal is to bring joy, excitement, fun and education to all computer programming hobbyists, tinkerers, and amateurs. I also enjoy helping and working with those who aspire at becoming masters of their craft.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Foursight
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Rotating Background
QB64 Member Project - Bowditch curve
QB64 Member Project - Rubix's Magic
QB64 Member Project - Color Triangles
QB64 Member Project - Line Thickness
QB64 Member Project - Score 4
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - ARB Checkers
QB64 Member Project - Quarto
QB64 Member Project - Spiro Roses
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Splatter
QB64 Member Project - Overboard
QB64 Member Project - Algeria Weather
QB64 Member Project - Swirl
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Isolation
QB64 Member Project - Martin Fractals version one
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Dreamy Clock
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Qubic
QB64 Member Project - Point Blank
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Input
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Pivot version two
QB64 Member Project - Connect Four
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Basic Dithering
QB64 Member Project - Touche
QB64 Member Project - Sabotage
QB64 Member Project - 9 Board
QB64 Member Project - Inside Moves
QB64 Member Project - Kings Court
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Color Rotating Text
QB64 Member Project - Exit
QB64 Member Project - Blokus
QB64 Member Project - Othello
QB64 Member Project - Domain
QB64 Member Project - Amazon
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Pivet version one
QB64 Member Project - Dakapo