forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Texture in OpenGL?

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Sat May 02, 2009 10:25 am    Post subject: Texture in OpenGL? Reply with quote

Hello,

I'm trying to apply a 1D texture to a triangle in OpenGL. However I'm just getting a white triangle at the moment which apparently implies that the texture is somehow incomplete. Can anyone see if some of the calls are incorrect or indeed if the order of the calls is wrong. Has anyone succesfully applied a texture using FTN95?

The code should produce a triangle with 4 vertical stripes, 2 red ones on the left and two blue ones on the right, on a black background.

Albert
Code:

winapp

      use openglmod
      include <clearwin.ins>,nolist
      integer i
      integer window
      i=winio@('%es%ca[Double Buffering]&')
      i=winio@('%sp%ww[no_border]%pv%^og[double]%lw',0, 0, 400, 400,opengl_proc,window)
      call Display()
      end



Please see next post for openglmod, for some reason I can't fit it all on one post


Last edited by acp693 on Sat May 02, 2009 10:34 am; edited 1 time in total
Back to top
View user's profile Send private message
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Sat May 02, 2009 10:33 am    Post subject: Reply with quote

Code:
module openglmod
      real,dimension(4,3)::arrcol
      integer:: texture1

      data arrcol(1,:)/0.76,0.2,0.02/
      data arrcol(2,:)/0.88,0.6,0.06/
      data arrcol(3,:)/1.0,1.0,0.01/
      data arrcol(4,:)/0.04,0.44,0.67/

contains
     
      subroutine display()
      include <opengl.ins>,nolist
      texture1=0
     
      call glClear(ior(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
      call glEnable(GL_TEXTURE_1D)
      call glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
      call glGenTextures(1,texture1)
      call glBindTexture(GL_TEXTURE_1D,texture1)
      call glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP)
      call glTexParameterf(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
      call glTexParameterf(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
      call glTexImage1D(GL_TEXTURE_1D,0,3,4,0,GL_RGB,GL_UNSIGNED_BYTE,arrcol)
      call glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)
     
      call glEnable(GL_TEXTURE_GEN_S)
     
      call glEnable(GL_TEXTURE_1D)
      call glBindTexture(GL_TEXTURE_1D,texture1)
      call glPushMatrix ()
     
      call glBegin(GL_TRIANGLES)!
     
      call glTexCoord1f(0.0)
     call glVertex3f(-25.0, -25.0, 0.0)
     call glTexCoord1f(0.5)
      call glVertex3f( 0.0, 25.0, 0.0)
     call glTexCoord1f(1.0)
      call glVertex3f( 25.0,  -25.0, 0.0)
     
     call glEnd()
     
      call glPopMatrix ()
      call glFlush()
      call swap_opengl_buffers()
      call glDisable(GL_TEXTURE_1D)
      end subroutine
     

      subroutine myinit ()
      include <opengl.ins>,nolist
      call glClearColor (0.0, 0.0, 0.0, 0.0)
      call glShadeModel (GL_SMOOTH)
      call glMatrixMode(GL_PROJECTION)
      call glEnable(GL_DEPTH_TEST) 
      call glLoadIdentity()
     
      call glOrtho (-50d0, 50d0, -50d0, 50d0, -50d0, 50d0)
      call glMatrixMode(GL_MODELVIEW)
      call glLoadIdentity ()
     
      end subroutine

      subroutine myReshape(w, h)
      include <opengl.ins>,nolist
      integer w,h
      double precision aspect_ratio
      if (h.NE.0) then
         aspect_ratio=real(w)/h

         call glViewport(0, 0, w, h)
         call glMatrixMode(GL_PROJECTION)
         call glLoadIdentity()
         if (w .LE. h) then
             call glOrtho (-50d0, 50d0, -50d0/aspect_ratio, &
     &                      50d0/aspect_ratio, -50d0, 50d0)
         else
             call glOrtho (-50d0*aspect_ratio, &
     &                      50d0*aspect_ratio, -50d0, 50d0, -50d0, 50d0)
         endif
         
         call glMatrixMode(GL_MODELVIEW)
         call glLoadIdentity ()

      endif
      end subroutine
     
      integer function opengl_proc()
      include <clearwin.ins>,nolist
      character*256 reason
      integer w,h
      reason=clearwin_string@('CALL_BACK_REASON')
      if(reason.eq.'SETUP')then
        call myinit()
      else if(reason.eq.'RESIZE')then
        w=clearwin_info@('OPENGL_WIDTH')
        h=clearwin_info@('OPENGL_DEPTH')
        call myReshape(w,h)
      else if(reason.eq.'DIRTY')then
        call display()
      end if
     
      opengl_proc=2
      end function
end module openglmod     
Back to top
View user's profile Send private message
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Sun May 03, 2009 6:58 am    Post subject: Solved Reply with quote

So I made some progress last night and now have a small example of how to lay a 1D texture on a triangle in OpenGL. There were several mistakes to find, the first was the shape of the array holding the pixel RGB values, second was replacing GL_UNSIGNED_BYTE with GL_FLOAT in the call to glTexImage1D. The third was the most frustrating, turning off hardware acceleration . The learning curve with OpenGL is quite steep, Does anybody know how to get debug information? regards Albert
Code:
winapp

      use openglmod
      include <clearwin.ins>,nolist
      integer i
      integer window
      i=winio@('%es%ca[1DTexture on a Triangle]&')
      i=winio@('%sp%ww[no_border]%pv%^og[double]%lw',0, 0, 400, 400,opengl_proc,window)
      call Display()
      end


Module is in next post
Back to top
View user's profile Send private message
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Sun May 03, 2009 7:03 am    Post subject: Reply with quote

Code:
module openglmod
      real(kind=1),dimension(3,4)::arrcol
      integer::texture1
     
      data arrcol(:,1)/0.7 ,0.0,0.0/
      data arrcol(:,2)/1.0,0.0,0.0/
      data arrcol(:,3)/0.0,0.0,1.0/
      data arrcol(:,4)/0.0,0.0,0.4/
contains
     
      subroutine display()
      include <opengl.ins>,nolist
     
      call glClear(ior(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
      call glPushMatrix ()
     
      call glBegin(GL_TRIANGLES)!
     
      call glTexCoord1f(0.0)
      call glVertex3f(-30.0, -30.0, 0.0)
      call glTexCoord1f(0.5)
      call glVertex3f( 0.0, 30.0, 0.0)
      call glTexCoord1f(1.0)
      call glVertex3f( 30.0,  -30.0, 0.0)
     
      call glEnd()
     
      call glPopMatrix ()
      call glFlush()
      call swap_opengl_buffers()
     
      end subroutine
     
     
      subroutine myinit ()
      include <opengl.ins>,nolist
      call glClearColor (1.0, 1.0, 1.0, 0.0)
      call glShadeModel (GL_SMOOTH)
      call glMatrixMode(GL_PROJECTION)
      call glEnable(GL_DEPTH_TEST) 
      call glLoadIdentity()
      call glOrtho (-50d0, 50d0, -50d0, 50d0, -50d0, 50d0)
      call glMatrixMode(GL_MODELVIEW)
      call glLoadIdentity ()
      texture1=0
      call glEnable(GL_TEXTURE_1D)
      call glGenTextures(1,texture1)
      call glBindTexture(GL_TEXTURE_1D,texture1)
      call glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
      call glTexImage1D(GL_TEXTURE_1D,0,3,4,0,GL_RGB,GL_FLOAT,arrcol)
      call glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP)
      call glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
      call glTexParameteri(GL_TEXTURE_1D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
      call glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
     
      end subroutine

      subroutine myReshape(w, h)
      include <opengl.ins>,nolist
      integer w,h
      double precision aspect_ratio
      if (h.NE.0) then
         aspect_ratio=real(w)/h

         call glViewport(0, 0, w, h)
         call glMatrixMode(GL_PROJECTION)
         call glLoadIdentity()
         if (w .LE. h) then
             call glOrtho (-50d0, 50d0, -50d0/aspect_ratio, 50d0/aspect_ratio, -50d0, 50d0)
         else
             call glOrtho (-50d0*aspect_ratio, 50d0*aspect_ratio, -50d0, 50d0, -50d0, 50d0)
         endif
         
         call glMatrixMode(GL_MODELVIEW)
         call glLoadIdentity ()
         
      endif
      end subroutine
     
      integer function opengl_proc()
      include <clearwin.ins>,nolist
      character*256 reason
      integer w,h
      reason=clearwin_string@('CALL_BACK_REASON')
      if(reason.eq.'SETUP')then
        call myinit()
      else if(reason.eq.'RESIZE')then
        w=clearwin_info@('OPENGL_WIDTH')
        h=clearwin_info@('OPENGL_DEPTH')
        call myReshape(w,h)
      else if(reason.eq.'DIRTY')then
        call display()
      end if
     
      opengl_proc=2
      end function
end module openglmod     
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Sun May 03, 2009 2:37 pm    Post subject: Reply with quote

Quote:
The third was the most frustrating, turning off hardware acceleration


Albert, do you do this yourself via control panel and display, or is there a way to do this from ftn95?
Back to top
View user's profile Send private message Visit poster's website
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Sun May 03, 2009 2:56 pm    Post subject: Reply with quote

John, I turned off hardware acceleration through control panel and display. I don't know if it's possible through FTN95. Without turning off hardware acceleration my triangles were just black shapes. This is only when using textures though.
On my laptop the code runs with hardware acceleration enabled. I don't understand why one computer should work and the other not.

I'm just starting in Opengl, the results are very good, but it is a steep learning curve. Fortunately I now have the techniques I need to swap from using Simpleplot for my animations to OpenGl.

John, I noticed through trawling through old threads, that you have used Opengl extensively, how are you debugging when using Opengl?

Regards

Albert
Back to top
View user's profile Send private message
JohnHorspool



Joined: 26 Sep 2005
Posts: 270
Location: Gloucestershire UK

PostPosted: Sun May 03, 2009 8:15 pm    Post subject: Reply with quote

Albert,

Code:
I don't understand why one computer should work and the other not


Unfortunately that is quite normal! The only way around it as you have found is to switch off graphics acceleration. It can be a real pain when users of the software don't know how to do this, thus my question to see if you had found an automated way. I don't know C++ but I do know that C++ can interrogate the graphics card and can open an OpenGL graphics window without hardware acceleration. There must be a way in FTN95 via the windows API ??

Quote:
how are you debugging when using Opengl?


With great difficulty! As you are aware by now the FTN95 debugger doesn't touch OpenGL. Thus when things went wrong (as they did), all I did was put write statements into the code at various positions to indicate how far the program had got before the crash, then write to the screen, data the program was attempting to pass to OpenGL. I soon learnt that data has to be checked and sanitised, OpenGL is intolerant to bad data!

Yes, its a steep initial learning curve, but well worth the effort, as the graphics can be absolutely stunning, and I thought my GDI graphics using %gr were good, but there's no comparison to OpenGL!

Good Luck,
John
Back to top
View user's profile Send private message Visit poster's website
acp693



Joined: 04 Sep 2006
Posts: 56

PostPosted: Mon Nov 29, 2010 1:14 pm    Post subject: Reply with quote

Although I started this thread sometime ago, I thought it might be interesting to report progress on my opengl application. The little test application i posted will still only display textures properly with hardware acceleration turned off using the Silverfrost compiler. However I've been playing with opengl in another language; Pascal. and the applications I've coded using that will run textures with hardware acceleration turned on full! This indicates that the opengl implementation in Silverfrost is not optimal.

Turning hardware acceleration off is always a problem, opengl is much slower, cpu usage often runs to 100% when using a largish viewport. And one isn't able to use any extensions that the graphics card may support, for example, my graphics card supports 3d textures, but only if hardware acceleration is turned on.

Regards

Albert
Back to top
View user's profile Send private message
GoldenHeat



Joined: 13 Jul 2011
Posts: 6

PostPosted: Thu Jul 14, 2011 9:15 pm    Post subject: Reply with quote

Al,

You are one of the first people I have heard of using Pascal with SF and a video converter. Are you saying that the Pascal code is what overloaded everything and caused you to determine the issue with SF? Again, these are important questions that I can answer in my email marketing campaign and I would love to have your knowledge and even include your namesake in the next edition of my newsletter.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group