Opengl glBitmap() question

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
Skywriter
Posts: 36
Joined: Jan 05, 2009 19:46
Location: Lithuania. Europe

Opengl glBitmap() question

Post by Skywriter »

I'm trying to make a font with glBitmap(), but cant figure out how it is properly to use it. In code below i should get a "!" font, but instead im getting scaterred pixels. If someone knows how properly use glBitmap please advice.

Code: Select all

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


Using FB

dim shared as byte rasters(12) =>{0, 0, 24, 24, 0, 0, 24, 24, 24, 24, 24,24,24}								  

declare sub myinit()
declare sub display()
declare sub myReshape()

screenres 640,480,32,1,GFX_OPENGL

sub myinit()

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    glClearColor(0.0, 0.0, 0.0, 0.0)

end sub

sub display()

    glClear(GL_COLOR_BUFFER_BIT)
    glColor3f(1.0, 1.0, 1.0)
    glRasterPos2i (20.5, 20.5)
    
    glBitmap 8, 13, 0.0, 0.0, 10.0, 0.0, @rasters(0)
    
    flip()

end sub

sub myReshape()

    glViewport(0, 0, 640, 480)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, 640, 0, 480, -1.0, 1.0)
    glMatrixMode(GL_MODELVIEW)

end sub

myReshape()
do

display()
loop

D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Opengl glBitmap() question

Post by D.J.Peters »

Code: Select all

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

dim shared as byte rasters(12) =>{0, 0, 24, 24, 0, 0, 24, 24, 24, 24, 24,24,24}

sub myReshape(w as integer,h as integer)
  glViewport(0, 0, w, h)
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  glOrtho(0,w,0,h,-1.0,1.0)
  glMatrixMode(GL_MODELVIEW)
end sub

sub myInit(w as integer=640,h as integer=480, bits as integer=24)
  screenres w,h,bits,,FB.GFX_OPENGL
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
  glClearColor(1.0, 1.0, 1.0, 1.0)
  myReshape(w,h)
end sub

sub myDisplay()
  glClear(GL_COLOR_BUFFER_BIT)
  glColor3f(1.0, 0.0, 0.0)
  glRasterPos2i(20, 20)
  glBitmap 8, 13, 0.0, 0.0, 10.0, 0.0, @rasters(0)
  flip()
end sub

'
' main
'
myInit()

while inkey=""
  MyDisplay()
  sleep 10
wend
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Opengl glBitmap() question

Post by D.J.Peters »

only for fun

Code: Select all

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

dim shared as ubyte ptr font8

sub myPrint(x as integer,y as integer, txt as string)
  dim as integer nChars = len(txt)
  if nChars<1 then return
  dim as integer h:screeninfo ,h
  for i as integer=0 to nChars-1
    glRasterPos2i(x,h-y):x+=8
    glBitmap(8,8, 0,0,0,0, Font8+txt[i]*8)
  next
end sub

sub myReshape(w as integer,h as integer)
  glViewport(0, 0, w, h)
  glMatrixMode(GL_PROJECTION)
  glLoadIdentity()
  glOrtho(0,w,0,h,-1.0,1.0)
  glMatrixMode(GL_MODELVIEW)
end sub

sub myInit(w as integer=640,h as integer=480, bits as integer=24)
  font8=allocate(2048)
  screenres 2048,8,1,,-1
  dim as integer i,j,k,r,c
  for i=0 to 255
    dim as ubyte ptr pS,pF=font8+j+7
    draw string (j,0),chr(i):k=0
    for r=0 to 7
      pS=ScreenPtr()+j+k
      for c=0 to 7
        if *pS then *pF or= 2^(7-c)
        pS+=1
      next
      pF-=1:k+=2048
    next
    j+=8
  next
  screenres w,h,bits,,FB.GFX_OPENGL
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
  glClearColor(0,0,0,1)
  myReshape(w,h)
end sub

myInit()

glClear(GL_COLOR_BUFFER_BIT)
glColor3f(rnd,rnd,rnd) : myPrint 20,20,"Hello world!"
glColor3f(rnd,rnd,rnd) : myPrint 20,40,"What's up my friends ?"
glColor3f(rnd,rnd,rnd) : myPrint 20,60,"glBitmap or not glBitmap !"
glColor3f(rnd,rnd,rnd) : myPrint 20,80,"That isn't the question."
while inkey=""
  flip:sleep 10
wend
relsoft
Posts: 1767
Joined: May 27, 2005 10:34
Location: Philippines
Contact:

Re: Opengl glBitmap() question

Post by relsoft »

I would like to add that glBitmap is very slow. ;*)
Skywriter
Posts: 36
Joined: Jan 05, 2009 19:46
Location: Lithuania. Europe

Re: Opengl glBitmap() question

Post by Skywriter »

Thank you. The second code compiles, but won't run. It says "Segmentation fault"...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: Opengl glBitmap() question

Post by D.J.Peters »

Skywriter wrote:... It says "Segmentation fault"...
A wrong memory access are possible i wrote it in two minutes.
(fix it or put it in a trash)

Joshy
Post Reply