Why do none of these work in my freebasic OpenGL programs.
Code: Select all
glDrawArraysInstanced
glGenBuffers
glBindBuffer
Code: Select all
glDrawArraysInstanced
glGenBuffers
glBindBuffer
Check out this demo: viewtopic.php?f=15&t=26105. There I use VBOs and VAOs. If you can't setup the VAOs correctly, glDrawArraysInstanced won't work right.Boromir wrote:Are VBOs and Instancing not available in freebasic's OpenGL?
Why do none of these work in my freebasic OpenGL programs.Code: Select all
glDrawArraysInstanced glGenBuffers glBindBuffer
Code: Select all
glGenBuffers(1, @vboId)
glBindBuffer(GL_ARRAY_BUFFER, vboId)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), verticess, GL_STATIC_DRAW)
glVertexPointer(3, GL_FLOAT, 0, 0)
glColorPointer( 3,GL_FLOAT,0,0)
glNormalPointer( GL_FLOAT,0,0)
Code: Select all
'opengl test program
dim as integer nc=370 'number of rows and columns of quad faces
dim as boolean vbomode=false 'try to use vbo
#include once "GL/gl.bi"
#include once "GL/glu.bi"
#include once "GL/glext.bi"
#include once "fbgfx.bi"
screenres 640,480,32,,2
glViewport 0, 0, 640, 480
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 45.0, 640.0/480.0, 0.1, 9000.0
glMatrixMode GL_MODELVIEW
glLoadIdentity
'glEnable GL_TEXTURE_2D
glShadeModel GL_FLAT
glClearColor 0.0, 0.0, 0.0, 0.5
glClearDepth 1.0
glEnable GL_DEPTH_TEST
glDepthFunc GL_LEQUAL
glEnable GL_LIGHT0
glEnable GL_LIGHTING
glEnable GL_COLOR_MATERIAL
glCullFace(GL_BACK)
glEnable(GL_CULL_FACE)
glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_COLOR_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY)
' Some useful helper functions
' This sub prints messages to the console for debugging
sub cPrint( byref text as string = "" )
dim as integer fn = freeFile()
open cons for output as fn
? #fn, text
close( fn )
end sub
' This sub exits the program with an error message
sub errorExit( byref msg as const string )
if( screenPtr() <> 0 ) then
screen( 0 )
end if
dim as integer w, h
screenInfo( w, h )
w *= 0.75
h *= 0.75
screenres( w, h )
width w / 8, h / 16
? "GL Error: ";
? msg
sleep()
end( 1 )
end sub
#macro glBindProc( n )
dim shared as PFN##n##PROC n
n = screenGLProc( #n )
if( n = 0 ) then
errorExit( "glBindProc(): failed to bind " & #n )
end if
#endmacro
glBindProc( glGenVertexArrays )
glBindProc( glBindVertexArray )
glBindProc( glGenBuffers )
glBindProc( glBindBuffer )
glBindProc( glBufferData )
glBindProc( glEnableVertexAttribArray )
glBindProc( glDisableVertexAttribArray )
glBindProc( glVertexAttribPointer )
glBindProc( glCreateShader )
glBindProc( glShaderSource )
glBindProc( glCompileShader )
glBindProc( glGetShaderiv )
glBindProc( glGetShaderInfoLog )
glBindProc( glDeleteShader )
glBindProc( glCreateProgram )
glBindProc( glAttachShader )
glBindProc( glLinkProgram )
glBindProc( glDetachShader )
glBindProc( glGetProgramiv )
glBindProc( glGetProgramInfoLog )
glBindProc( glUseProgram )
glBindProc( glDeleteProgram )
glBindProc( glDeleteBuffers )
glBindProc( glDeleteVertexArrays )
glBindProc( glGetUniformLocation )
glBindProc( glUniform1f )
glBindProc( glUniform1i )
glBindProc( glUniform2f )
glBindProc( glUniform2fv )
glBindProc( glUniform3fv )
glBindProc( glActiveTexture )
glBindProc( glUniformMatrix3fv )
glBindProc( glDrawArraysInstanced )
'==============================================================
'main
type vertex
dim as glfloat x,y,z
dim as glfloat r,g,b
dim as glfloat nx,ny,nz
end type
declare sub CreateCubes()
dim as GLuint vboId
dim shared box as uinteger
dim shared as vertex vertices(6*(nc*nc))
dim as vertex ptr verticess=@vertices(0)
declare sub cube(vertices() as vertex,i as integer,x as integer,y as integer,z as integer,r as integer, g as integer,b as integer)
dim as integer i
for x as integer=0 to nc-1
for z as integer=0 to nc-1
cube(vertices(),i,x*2,(rnd(1)*2),z*2,rnd(1),rnd(1),rnd(1))
i+=1
next
next
'=========================================================
'-------------------Vbo setup-----------------------------
if vbomode=true then
glGenBuffers(1, @vboId)
glBindBuffer(GL_ARRAY_BUFFER, vboId)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), verticess, GL_STATIC_DRAW)
glVertexPointer(3, GL_FLOAT, 0, 0)
glColorPointer( 3,GL_FLOAT,0,0)
glNormalPointer( GL_FLOAT,0,0)
else
'========================================================
'---------------------normal setup-----------------------
glVertexPointer(3,GL_FLOAT,sizeof(vertex),verticess)
glColorPointer( 3,GL_FLOAT,sizeof(vertex),@Vertices(0).r)
glNormalPointer( GL_FLOAT,sizeof(vertex),@Vertices(0).nx)
end if
'=========================================================
dim as integer num_indices = 6*i
do
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
glLoadIdentity
glRotatef 30, 1.0, 0,0
glRotatef 0, 0, 1.0, 0
glTranslatef -200,-20,-200
glDrawArraysInstanced(GL_TRIANGLES, 0, num_indices,1)
flip
loop until multikey(1)
sub cube(vertices() as vertex,i as integer,x as integer,y as integer,z as integer,r as integer, g as integer,b as integer)
i=i*6
for j as integer=0 to 5
vertices(i+j).r=r
vertices(i+j).g=g
vertices(i+j).b=b
vertices(i+j).nx=0
vertices(i+j).ny=1
vertices(i+j).nz=0
next
'top
vertices(i+0).x = -1.0+x
vertices(i+0).y = 1.0+y
vertices(i+0).z = -1.0+z
vertices(i+1).x = -1.0+x
vertices(i+1).y = 1.0+y
vertices(i+1).z = 1.0+z
vertices(i+2).x = 1.0+x
vertices(i+2).y = 1.0+y
vertices(i+2).z = -1.0+z
vertices(i+3).x = -1.0+x
vertices(i+3).y = 1.0+y
vertices(i+3).z = 1.0+z
vertices(i+4).x = 1.0+x
vertices(i+4).y = 1.0+y
vertices(i+4).z = 1.0+z
vertices(i+5).x = 1.0+x
vertices(i+5).y = 1.0+y
vertices(i+5).z = -1.0+z
end sub
You're welcome. Mmm, seems like you're mixing the old fixed function pipeline with the new programable pipeline. All the glDrawSomething() functions are meant to be used with shaders. See here for an explanation on how this works.Boromir wrote:Also how can I make the instanced drawing mode not stack them all in the same spot
Code: Select all
glUniformMatrix3fv( location, 1, GL_TRUE, @rotation.a )