|
I am sorry, but ALL buffers - display modes (?) are enabled in main OpenGl "event loop".
I though that glEnable(GL_STENCIL_TEST); // ENABLE the stencil buffer
is specifically to enable writing to the stencil buffer.
Am I wrong ?
window = glutCreateWindow("OpenGL - Base ");
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
I think I need to review all in old-fashioned "IBM flow chart" style - from top to bottom - from "vertex" to pixel on screen.
This OpenGL "pipe architecture" - from left to right - is just not working when it comes to stencilling.
What is confusing is mixing of hardwareand software.
"stencil works on pixel(s) "
Fore example
"stencil mask "defaults" to 1"
then I see stuff like this glStencilMask(0xFFFF);
I may also have modlelview stack messed-up.
|
|
|
|
|
 Here is my latest code.
I'll try to delete my debugging stuff. Hope I 'll not delete something important.
The code basically works, it does apply the stencil - to show only data INSIDE the stencil circle.
BUT
ONLY when I enable viewing of the stencil AND data being written to the color buffer.
I have highlighted the code. I was under the impression this is ONLY for viewing the stencil, but apparently not.
Obviously I do not have to re-able the color buffer , hence I get BOTH - stencil and the stencilled "fragment".
I have no idea how to proceed and where is my error.
glClear(
GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glDisable( GL_STENCIL_TEST);
glEnable(GL_STENCIL_TEST);
glClearStencil(0x0);
glClear(
GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glStencilMask(GL_TRUE); glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilFunc(GL_ALWAYS, 1, 1);
parameter_stencil = 42;
parameter_stencil = Stencil(parameter_stencil); glFlush();
if (parameter_stencil == 0) {
printf(
"\nStencil full circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_EQUAL, 1, 1);
} else {
printf(
"\nStencil last circle parameter %i @function %s @line %i",
parameter_stencil, __FUNCTION__, __LINE__);
glStencilFunc(GL_NOTEQUAL, 1, 1);
}
{
OpenGL_Render_Plus_IMG_Axis(); }
from here I am not sure how to display only the rendered fragment
I get both stencil and fragment ONLY when writing to color buffer is enabled
glStencilMask(GL_FALSE);
glClear(
GL_STENCIL_BUFFER_BIT );
glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
glClear(
GL_STENCIL_BUFFER_BIT );
glFlush();
|
|
|
|
|
maybe professionals here at codeproject have a hint for me.
Please see following example:
#include <iostream>
using namespace std;
int c, d;
#define Circumference c
#define Diameter d
int main ()
{
cout << "Please enter diameter: ";
cin >> Diameter;
Circumference = 3.14 * Diameter;
cout << " Circumference is " << Circumference << endl;
return 0;
}
My IDE (Understand) report possibilities always break down the #define to it's origin. So all reports state that function main() uses variables 'c' and 'd'.
But what I like to have is the real used expression in the function source code. So report shoud show that main() uses 'Circumference' and 'Diameter' and not 'c' and 'd'.
Is there any tool out there (for Windows 10 OS) which is able to do this ?
Many thanks for any hint!
'There are 10 types of people in this world, those who understand binary and those who dont.'
|
|
|
|
|
I am not sure I understand what the problem is. I have just built and run your code successfully. But why are you doing it that way, what is wrong with: the following?
#include <iostream>
using namespace std;
int main ()
{
float Circumference;
float Diameter;
cout << "Please enter diameter: ";
cin >> Diameter;
Circumference = 3.14f * Diameter;
cout << " Circumference is " << Circumference << endl;
return 0;
}
|
|
|
|
|
In C/C++ lines that start with # are preprocessor directives. What you need to understand about the preprocessor is what it basically does is text replacement. So what happens is that your C/C++ program text, lets call it program.cpp, gets passed through the preprocessor, and the output of that gets passed to the compiler proper.
So lets say you have
#define Circumference c
#define Foo 10
cout << Circumference << " " << Foo << end;
When it gets to the compiler, it sees this:
cout << c << " " << 10
So the compiler proper never sees the #define statements.
The fine print:
The standards for C and C++ don't specify how the preprocessor is implemented, just how it should behave. Most compilers have chosen to implement the preprocessor as a separate executable, but it certainly doesn't have to be that way.
Keep Calm and Carry On
|
|
|
|
|
Why don't you do this instead:
int main( void )
{
float Diameter;
float Circumference;
cout << "Please enter diameter: ";
cin >> Diameter;
Circumference = 3.14 * Diameter;
cout << " Circumference is " << Circumference << endl;
return 0;
} Then it is more standard, and you also get what you want.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
Great minds think alike!
Sorry about that. I went from the OP to Reply, with no stops in between.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Done it myself occasionally.
|
|
|
|
|
I've found in a C function, from a Linux library a function: get_osfhandle:
handle = get_osfhandle(fd);
And it is declared up in the C file like this:
HANDLE get_osfhandle(int);
but I got a link error:
error LNK2019: unresolved external symbol "void * __cdecl get_osfhandle(int)" (?get_osfhandle@@YAPAXH@Z) referenced in function ...
I commented that line, HANDLE get_osfhandle(int); , and without this declaration, I got the error from post subject. Of course, I have included io.h header, like msdn said: _get_osfhandle | Microsoft Docs[^]
But I got the same errors. I have tried to include <windows.h>, seem to be useless ... how to overcome this error ?
|
|
|
|
|
Microsoft have helpfully changed the name, it is now _get_osfhandle (with a leading underscore), as defined in io.h.
|
|
|
|
|
|
Yes, I was well aware of that. I have been using WSL for some time, but maybe I should upgrade to WSL2. Thanks for the link.
|
|
|
|
|
Since today is my day to ask stupid questions, here is another one.
I have some understanding how to pass a function as a parameter.
I can even add and use ONE parameter to such function.
I do not understand the
- syntax. how to add more parameters.
What I am also missing is syntax on how to read / access , verify passed parameters.
I need to make a decision based on the parameter.
void OpenGL_Stencil(void (*f)(int parameter));
void OpenGL_Stencil(void (*Stencil)(int parameter)) {
Stencil(0);
PS Take your time , my interned connection is like a yo-yo today.
modified 20-Apr-20 9:24am.
|
|
|
|
|
To add more parameters, just extend the argument list: (int parameter1, int parameter2) and so on.
All you have at this point is a declaration and definition of the function OpenGL_Stencil . Its parameter is a function that returns void and takes one int parameter. The next step is to implement a function with that signature and pass it as an argument to OpenGL_Stencil .
void Something(int value) { }
After which invoking OpenGL_Stencil(Something) should cause OpenGL_Stencil to invoke Something .
|
|
|
|
|
Yes, I got that far.
I need to read the passed parameter.
<pre>void OpenGL_Stencil(void (*Stencil)(int parameter)) {
glClear(GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
glStencilFunc(GL_ALWAYS, 1, 1); glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
Stencil(0); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
this is where I am missing how to test the parameter
glStencilFunc(GL_EQUAL, 1, 1); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
|
|
|
|
|
I'm not certain what you're asking here.
Inside OpenGL_Stencil , the name of the parameter that was passed in (a function) is Stencil . If you're talking about the int parameter for Stencil , OpenGL_Stencil has to provide that itself. It isn't the parameter associated with Stencil , because that only describes Stencil 's function signature and could actually be left out, the same as in a function declaration:
void OpenGL_Stencil(void (*Stencil)(int))
If OpenGL_Stencil doesn't know what value to pass to Stencil, you could provide it like this:
void OpenGL_Stencil(void (*Stencil)(int), int value) after which you can invoke
Stencil(value)
|
|
|
|
|
May try it this way
the parameter is a function - Stencil
such function is passed with its own parameter - such in Stencil(parameter)
how do I access that parameter "value" in OpenGL_Stencil function?
I need to do
if(Stencil(parameter == x )
|
|
|
|
|
You have to pass it as a parameter to OpenGL_Stencil , the way I described in the second half of my post.
|
|
|
|
|
OK, I think I have the concept - have passed function return value insed of being void.
Now I am still not sure about the proper syntax.
Here is my code
OpenGL_Stencil_Circle_Build(parameter); returns parameter OK
OpenGL_Stencil(OpenGL_Stencil_Circle_Build(6)); wrong syntax
And here is the error
Description Resource Path Location Type
Invalid arguments '
Candidates are:
int OpenGL_Stencil(void (*)(int))
' A_STENCIL.cpp /A_STENCIL/src line 766 Semantic Error
invalid conversion from ‘int’ to ‘void (*)(int)’ [-fpermissive] A_STENCIL.cpp /A_STENCIL/src line 766 C/C++ Problem
The declaration may be the issue ?
int OpenGL_Stencil(void (*f)(int parameter));
Could somebody please reply with correct syntax or help me with declaration ?
|
|
|
|
|
I believe that this
invalid conversion from ‘int’ to ‘void (*)(int)
means that you are passing an int argument when a function argument is expected, specifically a function that takes one int parameter and returns void .
The problem appears to be
OpenGL_Stencil(OpenGL_Stencil_Circle_Build(6))
where, based on previous posts in this thread, I assume you want OpenGL_Stencil to call OpenGL_Stencil_Circle_Build with a value of 6 . If that's the case, you did not read my previous post very carefully, because you need to do it as follows:
OpenGL_Stencil(OpenGL_Stencil_Circle_Build, 6)
where OpenGL_Stencil is defined as
void OpenGL_Stencil(void (*func) (int), int arg)
{
func(arg); }
|
|
|
|
|
It is now working, however, the mechanics are NOT what you have presented.
The initial problem was to pass a parameter to the passed function such as
Stencil(parameter); // parameter);
Now in my poor English interpretation I have
A function OpenGL_Stencil with first argument int (*Stencil)(int) and second argument int parameter
The OpenGL_Stencil returns int which is not currently used.
The first argument - function takes the second argument as a -parameter- and returns it.
The returned value is used to switch the code which follows.
That was the original task , however, I could just use the passed second argument to do the switching, without the use of the return value.
But that is just the way I like to make sure the code is actually processing the first argument - the function.
I believe my original misunderstanding was trying to pass the second argument - parameter _ as a argument to the first argument - the function.
Next task - pass multiple arguments or a pointer....
Many thanks for your help, really appreciate it.
Cheers.
|
|
|
|
|
|
Just FYI, this is NOT a repost.
As usual I have posted the original in WRONG pew.
However, I found another even weirder failure of simple math case and I really do not have a clue what I am doing wrong.
Are my local variable assignments incorrect ?
Is "printf" lying to me ?
Here is the entire test code
#define MAX_CIRCLES 5
struct TAG_Circles {
float radius;
float center;
float center_x;
float center_y;
} REAL_Circle[MAX_CIRCLES], IMG_Circle[MAX_CIRCLES];
void OpenGL_Stencil_Circle_Build(void);
void OpenGL_Stencil_Circle_Build(void) {
int index = 5;
{
float radius = IMG_circle[index].radius;
float center_x = IMG_circle[index].center_x;
float center_y = IMG_circle[index].center_y;
printf("\n Last circle #%i radius struct %f radius %f", index,
REAL_Circle[index].radius, radius);
printf("\n Last circle #%i center_x struct %f center_x %f", index,
REAL_Circle[index].center_x, center_x);
printf("\n Last circle #%i center_y struct %f center_y %f", index,
REAL_Circle[index].center_y, center_y);
}
}
Here is the output
Last circle #5 radius struct 0.065789 radius 0.131579
Last circle #5 center_x struct 0.000000 center_x 0.118421
Last circle #5 center_y struct 0.000000 center_y 0.000000
The questions are NOT what I am trying to accomplish with the code ,
the questions are:
1. why values printed FROM struct DO NOT match assigned values ?
2. why is "radius" TWICE of the value assigned from struct?
PS
Only
radius struct 0.065789 is of correct value.
Cheers
|
|
|
|
|
Could it be because you're assigning radius from IMG_circle but printing the value of REAL_circle ?
Keep Calm and Carry On
|
|
|
|