OpenGL texture issues

New to FreeBASIC? Post your questions here.
thebigh
Posts: 8
Joined: Dec 14, 2018 11:11

OpenGL texture issues

Postby thebigh » Jun 02, 2019 13:38

Hello all, I am working my way through the NeHe OpenGL tutorials and have got stuck on part 6, where we learn how to load textures. The first issue is that bmpload.bi fails to load any textures; it always returns a zero pointer for the texture pointer.

So I switched to createtex.bi, which does load bitmaps, but with a warning message: createtex.bi(39) warning 3(1): Passing different pointer types, at parameter 2 of GLGENTEXTURES()

Here is my code, which is supposed to draw a single square textured with a funny picture of a cat I found on reddit. Below that is what the program actually produces- it is very weird.

Code: Select all

#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include once "createtex.bi"

const NULL = 0

FUNCTION Shell_Starting_Window_Print_Line(BYREF txt AS STRING) AS INTEGER
  FUNCTION = SHELL("echo " + txt)
END FUNCTION

function load_texture(byref image_file as string, byval w as integer, byval h as integer) as GLuint
   dim image(w * h * 2 + 4) as ushort   ' set up a big enough array for our image
   bload image_file, @image(0)          'load it
   dim ret as GLuint                 'return value
   'create and bind the texture ( courtesy of lillo )
   ret = CreateTexture(@image(0), TEX_MASKED or TEX_MIPMAP )
   'return value in case we need multiple texture

   return ret
end function

   dim shared texture(0) as GLuint               '' Storage For One Texture ( NEW )
   
   screen 18, 16,,&h2
   '' ReSizeGLScene
   glViewport 0, 0, 640, 480                      '' Reset The Current Viewport
   glMatrixMode GL_PROJECTION                     '' Select The Projection Matrix
   glLoadIdentity                                 '' Reset The Projection Matrix
   gluPerspective 45.0, 640.0/480.0, 0.1, 100.0   '' Calculate The Aspect Ratio Of The Window
   glMatrixMode GL_MODELVIEW                      '' Select The Modelview Matrix
   glLoadIdentity                                 '' Reset The Modelview Matrix
   '' Jump To Texture Loading Routine
   texture(0)=load_texture("funnycat.bmp",128,128)
   Shell_Starting_Window_Print_Line( str(texture(0)) )
   if texture(0)=NULL then
       Shell_Starting_Window_Print_Line("Could not load texture")
      end 1
   end if

   glEnable GL_TEXTURE_2D                         '' Enable Texture Mapping ( NEW )
   glShadeModel GL_SMOOTH                         '' Enable Smooth Shading
   glClearColor 0.0, 0.0, 0.0, 0.5                '' Black Background
   glClearDepth 1.0                               '' Depth Buffer Setup
   glEnable GL_DEPTH_TEST                         '' Enables Depth Testing
   glDepthFunc GL_LEQUAL                          '' The Type Of Depth Testing To Do
   glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST    '' Really Nice Perspective Calculations
   
   
   do
      glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT      '' Clear Screen And Depth Buffer
      glLoadIdentity                                          '' Reset The View
      glTranslatef 0.0, 0.0, -4.0                             '' Move Into The Screen 4 Units
      
      glBindTexture GL_TEXTURE_2D, texture(0)                 '' Select Our Texture
      
      glBegin GL_QUADS
         ' Front Face
         glTexCoord2f 0.0, 0.0 : glVertex3f -1.0, -1.0,  1.0  '' Bottom Left Of The Texture and Quad
         glTexCoord2f 1.0, 0.0 : glVertex3f  1.0, -1.0,  1.0  '' Bottom Right Of The Texture and Quad
         glTexCoord2f 1.0, 1.0 : glVertex3f  1.0,  1.0,  1.0  '' Top Right Of The Texture and Quad
         glTexCoord2f 0.0, 1.0 : glVertex3f -1.0,  1.0,  1.0  '' Top Left Of The Texture and Quad
      glEnd
      
       flip
   loop while inkey = ""


Image Hilarious cat

Image This appears to be the bottom right quarter of the image. And why are there black gaps everywhere?

What am I doing wrong?
Kuan Hsu
Posts: 424
Joined: Sep 16, 2007 15:12
Location: Taiwan

Re: OpenGL texture issues

Postby Kuan Hsu » Jun 03, 2019 12:15

I think you are using 64-bits FreeBASIC compiler......

Please Modifify createtex.bi, replace uinteger with ulong ( 64bits to 32bits )
thebigh
Posts: 8
Joined: Dec 14, 2018 11:11

Re: OpenGL texture issues

Postby thebigh » Jun 03, 2019 15:43

Thank you, Kuan Hsu. That worked perfectly. I appreciate the help.

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests