I stayed up all night and finally got it working. I found this c program for making dynamic textures in opengl.
I have been hacking away at it over and over till I got it working. Woohoo!!! I am so excited.
This is neat, but the code is messy as you see me commenting and trying different things. The c source is in there but it is a mess.
To excited to clean it up at the moment, but will later. For now here it is, it draws a cube, it then makes that a texture and you see it update
while the cube rotates around.
I will clean it up later and make it easier to follow, but this is neat that it works so well and is not slow at all!!
Petr Schreiber
20-06-2007, 19:36
:o :o :o,
amazing work kryton9!
I am hardly searching words! I am leaving back to the mountains, where I will spent rest of life on meditations, because new GL boss is here ;) Great!
Did you know render to texture is fastest approach to perform motion blur too ?
Just save few frames back and than render it all at once ! I think NFS: Most Wanted has similar approach for example.
Bye,
Petr
Thanks guys, glad you all got excited by the possibilities too! It just shows how cool thinBasic is and how well tbgl is written.
Welcome back Petr. I never thought about it for blur sounds great!
Matthew, I haven't played with 4gl, but will install it and try out your program. Just by looking at the link you did a great job cleaning up the mess!!!
I am sure now that this technique works and performance is not a factor, we will see lots of cool programs coming in the future!!
All I can say is that in trying all of the languages I have been trying lately, it is hard to match thinBasic. TBGL really makes opengl fun to use And they are both under development. Already it is my favorite language to use. And keeps getting better and better every day. So I appreciate all you guys have done.
I was lured by OOP programming, but when you see the reality... I think the reality is that programmers like to write and create objects. They are fun to make. But it seems very few objects get used by others. In Delphi, with the components, it is different. THey are useful and do get used. But in c++. Everyone has written their own 3d math library. Why? Why not use one great library? Because of the headaches of doing so and also, like I said, I think people like making objects.
With udt's and global variables, you can have much nicer looking code that is easier to go back to in the future. I am still learning the other languages because I know when I get a small device, I would like to write for it. If it wasn't for that thinBasic would be my only focus.
Anyways just wanted to give a big thanks to you guys.
Petr Schreiber
21-06-2007, 21:45
Thanks kryton :),
I am very happy you feel it like this. And it is pleasure to see how you get used to tB and master it more and more.
Here is just TBGLified version of your latest render2tex code:
' Demo 2 of Rendered Text by Kryton9
' based on the great base code from
' Demonstration of rendering to texture
' Copyright (C) 2005 Julien Guertault
' -- Just TBGLified a bit by Psch
Uses "TBGL"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_gl.inc"
#INCLUDE "%APP_INCLUDEPATH%\thinbasic_glu.inc"
%SIZE = 256
dim texture(3 * %SIZE * %SIZE) as GLvoid
dim texture_id as GLuint = 1
dim window_width as LONG = 500
dim window_height as LONG = 500
dim speed as double = 75
dim sizze as double = 2
dim hWnd as dword
hWnd = TBGL_CreateWindowEX("Render to texture - press ESC to quit", window_width, window_height, 32, 0)
TBGL_ShowWindow
tbgl_UseTexture 1
tbgl_BindTexture texture_id
glTexImage2D (%GL_TEXTURE_2D, 0, %GL_RGB, %SIZE, %SIZE, 0, %GL_RGB, %GL_UNSIGNED_BYTE, texture)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_MIN_FILTER, %GL_LINEAR)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_MAG_FILTER, %GL_LINEAR)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_WRAP_S, %GL_CLAMP)
glTexParameteri (%GL_TEXTURE_2D, %GL_TEXTURE_WRAP_T, %GL_CLAMP)
dim FrameRate as number
tbgl_GetAsyncKeyState(-1) ' Resets key status before checking
while tbgl_IsWindow(hWnd)
FrameRate = tbgl_GetFrameRate
tbgl_ClearFrame
tbgl_Translate (0, 0, -10)
tbgl_Rotate (30, 1, 0, 0)
tbgl_Rotate (GetTickCount/speed, 0, 1, 0)
'/* Define a view-port adapted to the texture */
glMatrixMode(%GL_PROJECTION)
tbgl_resetMatrix
gluPerspective (20, 1, 5, 15)
glViewport(0, 0, %SIZE, %SIZE)
glMatrixMode(%GL_MODELVIEW)
'/* Render to buffer */
tbgl_BackColor 255, 175, 1, 0
glClear (%GL_COLOR_BUFFER_BIT or %GL_DEPTH_BUFFER_BIT)
plane()
'Cube ()
glFlush ()
'/* Copy buffer to texture */
glCopyTexSubImage2D(%GL_TEXTURE_2D, 0, 5, 5, 0, 0, %SIZE - 10, %SIZE - 10)
'/* Render to screen */
glMatrixMode(%GL_PROJECTION)
tbgl_resetMatrix
gluPerspective (20, window_width / window_height, 5, 15)
tbgl_Viewport(0, 0, 1, 1)
glMatrixMode(%GL_MODELVIEW)
tbgl_BackColor 0,0,0,0
glClear (%GL_COLOR_BUFFER_BIT or %GL_DEPTH_BUFFER_BIT)
'plane()
Cube ()
TBGL_DrawFrame
if tbgl_GetWindowKeyState( hWnd, %VK_ESCAPE) THEN exit while
if tbgl_GetWindowKeyState( hWnd, %VK_UP) THEN speed = iif( speed <= 0, 1, speed + 1/FrameRate)
if tbgl_GetWindowKeyState( hWnd, %VK_DOWN) THEN speed -= 1/FrameRate
if tbgl_GetWindowKeyState( hWnd, %VK_RIGHT) THEN sizze += 5/FrameRate
if tbgl_GetWindowKeyState( hWnd, %VK_LEFT) THEN sizze -= 5/FrameRate
if tbgl_GetWindowKeyState( hWnd, %VK_SPACE) THEN
sizze = 2
speed = 75
end if
tbgl_setwindowtitle (hwnd,"ESC to quit speed = "+format$(speed,"0.00")+" size = "+format$(sizze,"0.00"))
wend
TBGL_DestroyWindow ' Closes TBGL window
sub Cube()
tbgl_BeginPoly %GL_QUADS
tbgl_TexCoord2d (0, 0) : tbgl_Vertex (-1, -1, -1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex (-1, -1, 1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex (-1, 1, 1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex (-1, 1, -1)
tbgl_TexCoord2d (0, 0) : tbgl_Vertex ( 1, -1, -1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex ( 1, -1, 1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex ( 1, 1, 1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex ( 1, 1, -1)
tbgl_TexCoord2d (0, 0) : tbgl_Vertex (-1, -1, -1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex (-1, -1, 1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex ( 1, -1, 1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex ( 1, -1, -1)
tbgl_TexCoord2d (0, 0) : tbgl_Vertex (-1, 1, -1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex (-1, 1, 1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex ( 1, 1, 1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex ( 1, 1, -1)
tbgl_TexCoord2d (0, 0) : tbgl_Vertex (-1, -1, -1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex (-1, 1, -1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex ( 1, 1, -1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex ( 1, -1, -1)
tbgl_TexCoord2d (0, 0) : tbgl_Vertex (-1, -1, 1)
tbgl_TexCoord2d (0, 1) : tbgl_Vertex (-1, 1, 1)
tbgl_TexCoord2d (1, 1) : tbgl_Vertex ( 1, 1, 1)
tbgl_TexCoord2d (1, 0) : tbgl_Vertex ( 1, -1, 1)
tbgl_EndPoly
end sub
sub plane()
tbgl_BeginPoly %GL_QUADS
tbgl_Color 255, 0, 0 : tbgl_TexCoord2d 0,0 : tbgl_Vertex -sizze , -sizze, 0
tbgl_Color 0 , 255, 0 : tbgl_TexCoord2d 0,1 : tbgl_Vertex sizze , -sizze, 0
tbgl_Color 0 , 0, 255 : tbgl_TexCoord2d 1,1 : tbgl_Vertex sizze , sizze, 0
tbgl_Color 255, 200, 0 : tbgl_TexCoord2d 1,0 : tbgl_Vertex -sizze , sizze, 0
tbgl_EndPoly
tbgl_Color 255, 175, 0
end sub
Bye,
Petr