OpenGL dot / cross Functions

Just starting out? Need help? Post your questions and find answers here.
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

OpenGL dot / cross Functions

Post by BillBoard_67 »

Hi Everyone,

I'm new on this forum and it's my first post !

In the PB Doc, it's mentionned that native OpenGL functions are supported in PB by adding a simple underscore (glbegin_ , gelEnd_ ....)

The dot and Cross fonctions are not recognized. Is it normal ? Is there any limitations around the OpenGL fonctions usable under PB ?

Is there another mean to complete dot and cross calculations on the GPU (for intensive procedural generation) without dot and cross OpenGl Functions ?

Thanks for your answers.
DarkDragon
Addict
Addict
Posts: 2228
Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:

Re: OpenGL dot / cross Functions

Post by DarkDragon »

There is no dot or cross function in OpenGL. These functions are inside GLSL for shading. You'd have to create a shader, compile it, link it and render some polygons such that it will be executed.

https://www.purebasic.fr/english/viewto ... 47#p578247

Something like that. Simply search for GLSL and you'll find examples for sure.
bye,
Daniel
User avatar
luis
Addict
Addict
Posts: 3876
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: OpenGL dot / cross Functions

Post by luis »

PB imports the legacy part of the OpenGL function, up to version 1.1.
PB also creates a context in compatibility mode, where your OpenGL driver makes available all the OpenGL functions (modern and legacy) to be used together. This is true on Linux and Windows, there are limitations under MacOS because Cupertino does not care about OpenGL anymore.

So, with plain PB you can write OpenGL programs old-style using the immediate mode of OpenGL, or write modern OpenGL programs mixed with deprecated functions if the driver makes this option available. But you have to import the addresses of the functions above 1.1 by yourself manually, else you can't use them.

Dot and Cross product are two mathematical operations which are not part of the OpenGL library, you must write your own or use a library implementing them. Even in other languages it's the same thing.

In the forum you can find more than one solution for importing the modern functions, and for implementing math functions for dot/cross product. Also vectors, matrices, etc.

Just search for "OpenGL" and try all the stuff.

My own module for Windows and Linux which takes care of all these problems and more it's available here if interested -> https://www.purebasic.fr/english/viewtopic.php?t=81764
Last edited by luis on Wed Feb 21, 2024 1:15 pm, edited 1 time in total.
"Have you tried turning it off and on again ?"
A little PureBasic review
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

Re: OpenGL dot / cross Functions

Post by BillBoard_67 »

Hi,

Thanks Luis And Daniel for your answers.

You're right. dot and cross are parts of the GLSL (not the openGL strictly ) .

My objective is to generate Perlin Noise for Procedural Map generation. With a CPU based algorithm, the performance is very limited when it comes to arrays of 1000 x 1000 tiles and more . By using SIMD based assembly code, we would divide the delay generation by 4 (approximately) .

The calculation of interpolations and vector products seems to be very "Time_Processor consuming", since the calcuations are made on float and d values (with lots of multiplications and divisions).

The idea is to use the GPU to make these calculations and then save the results in an array used by the program in less intensive tasks.

I'll take a look to your links for more ideas or other solutions ;)
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: OpenGL dot / cross Functions

Post by Olli »

"cross" I ignore if it exist. But "dot" exists in openGL. But it is as slow as there are lots of pixel colors to change. For best performances, maybe use a 3D mesh you display without texture in... "dot mode" (it seems that the 3 modes dot/line/textured exist).

Do a browser research about VBO to understand how to create an array of vertices whom you use only 2 of the 3 axis.

And the time is missing for you to test quickly, use the native Ogre3D library to create your first schemes, and test the speedness...
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

Re: OpenGL dot / cross Functions

Post by BillBoard_67 »

Hi Olli,

Thanks for your answer.

You mean that i should send an array of data to the Vertex Buffer, which will do the calculcations ? How can i access the data after calculations ? Any idea ?

Moreover, to use VBO, i'll need to use some OpenGL functions such glGenBuffers..... which are not recognized by PB :(
Olli
Addict
Addict
Posts: 1071
Joined: Wed May 27, 2020 12:26 pm

Re: OpenGL dot / cross Functions

Post by Olli »

glGenBuffers_() is detected by the whole version of pureBasic.

Which calculation do you talk about ?
-> if it is 3D, openGL or native Ogre3D are okay.

If it is to for more general purposes, I join the advice of DarkDragon.

Normally yes you can access to the result. If you can output a pointor value from a shader, you specify the buffers address got in the shader program.
pjay
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Mar 30, 2006 11:14 am

Re: OpenGL dot / cross Functions

Post by pjay »

Hi, and welcome to the forum.
The idea is to use the GPU to make these calculations and then save the results in an array used by the program in less intensive tasks.
I've already written what you're asking for here - I can post it if wish, or you can figure it out for yourself (it can be half the fun :) )
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

Re: OpenGL dot / cross Functions

Post by BillBoard_67 »

Hi Olli and Pjay,

I've made some tests with glGenBuffers() function , and PB sens back an error message "glGenBuffers_() is not a function, map pr list ...."

Do you have some code to study to understand what you mean when you say "you specify the buffers address got in the shader program"

pjay, It would help me a lot if I can read your code . I have made a lot of days working on this question with no results. I Have studied codesources of GIMP and GODOT to try understand how they generate perlin noise . :(
pjay
Enthusiast
Enthusiast
Posts: 171
Joined: Thu Mar 30, 2006 11:14 am

Re: OpenGL dot / cross Functions

Post by pjay »

I just posted it into tips and tricks section.

It's not 'pretty' code I'm afraid (it's generally not my style for personal code), but I hope it works for you and you find it useful. :)
BillBoard_67
User
User
Posts: 10
Joined: Wed Feb 21, 2024 9:57 am

Re: OpenGL dot / cross Functions

Post by BillBoard_67 »

Thanks pjay for your post !!

I put a link here to your post for other users : https://www.purebasic.fr/english/viewtopic.php?t=83634

I'm going there now to see what it looks like . I'm curious to see how you did:)
Post Reply