Tag Archives: C/C++

OpenGL result white screen solution

Recently, the graphics department is doing computer experiment, and it needs to use OpenGL experimental operation, but my computer is not good enough.
Cannot display the correct result, each time is a white screen, can not display the desired result.
1. Problem: OpenGL is white
2. Environment: Win7 system, 64-bit. The model is Acer E1-571G, and the graphics card is Intel + Nvidia 710M 2G, VC6.0 and VS2008.
3, solution: enter the NVIDIA control panel (my computer directly desktop anti-key has), as shown in the picture global Settings to select high performance, application. Perfect solution, (*^__^*) Hee hee…

 
4, thinking: this setting should be the meaning of shielding set only open alone show, it should consume more power. So I tinkered with this control panel,
Here is a program setting, select Custom Settings, results… Useless, alas, forget it, solve good, first like this.
Have same problem to be able to refer to.

Reproduced in: https://www.cnblogs.com/hahanonym/p/3404884.html

The solution of using OpenGL’s Glu Library in qt5.2 under win7

 

I recently used QT5.2 to learn OpenGL in Windows 7. I recently used QT5.2 to learn OpenGL in Windows 7. I recently used QT5.2 to learn OpenGL.

‘GluPerspective’ was not declared in this scope. The version of Qt used in this article is
Qt 5.2.0 for Windows 32-bit (MinGW 4.8, OpenGL, 689 MB)
(Info), you can see the Qt version download information under various platforms from the Qt official website http://qt-project.org/downloads.

I searched the web for the following related solutions, which are for lower versions of Qt, such as this article: The GLU header file is not available for common Qt errors. I gave it a try and finally solved the problem with QT5.2 under Windows 7.
1. Add a header file to the source file of the glu library that references functions like gluPerspective: #include< gl/glu.h>
This step is necessary. For some reason, Glu32 libraries that start with glu and use OpenGL under QT5.2 also need to include GL /glu.h headers, while OpenGL32 libraries that start with GLL in OpenGL do not need to include headers.
Download Glut. lib and Glut32. lib and copy them to your Qt installation directory in Qt5.2.0\5.2.0\mingw48_32\lib, so that the Qt compiler will automatically search for the corresponding library files in the Qt installation directory.
This step may not be necessary.
Finally, I have tried the OpenGL under Qt (2) in my Qt5.2 environment (2) and the OpenGL example in C++ GUI Programming with Qt4(2nd Edition) Chapter 20. Make sure that after the above configuration, GluPerspective (45.0,(GLFloat)width/(GLFloat)height,0.1,100.0); And gluPickMatrix (GLdouble (pos) (x)), GLdouble (viewport [3] – pos. Y ()), 5.0, 5.0, viewport); These two lines of code work.

Reproduced in: https://www.cnblogs.com/lvdongjie/p/4775473.html

Optimization method of vs2017 starting speed

VS as the first editor of the universe, especially after the release of 2017 should attract countless programmers to use, but the VS2017 start speed is slow, so specially studied the VS2017 to accelerate the start of the method. The following methods are Microsoft official advice, you can try.
Uninstall program
You can uninstall little-used individual projects from Solution Explorer by using the right-click context menu.
Refactoring the solution
You can split the solution into smaller solution files and include common projects in these files. This refactoring can significantly reduce the memory usage of the workflow. In addition, the smaller the solution, the faster it loads.
Configure debug options
If you often run out of memory during a debugging session, you can optimize performance by changing one or more configurations.
Enable “Only My Code”
The simplest optimization is to enable the “Only My Code” feature, which only loads your project’s symbols. With this feature enabled, you can save a lot of memory when debugging managed applications (.NET). This option is enabled by default for some project types.
To enable “Only My Code”, select “Tools”>; “Options” & gt; “Debugging” & gt; “General”, then select “Enable My Code Only”.
Specifies the symbol to load
For native debugging, loading the symbol file (.pdb) takes up a lot of memory resources. You can save memory by configuring the debugger symbol Settings. Typically, configure the solution to load only modules in your project.
To specify symbol loading, select Tools>; “Options” & gt; “Debugging” & gt; “Symbol.”
sets the option to “Specify modules only” instead of “All modules” and then specifies the payload to load. When debugging, you can also right-click on a particular module in the Modules window to include its display in the system load. (To open the window while debugging, select Debug>; “Window” & gt; “Modules.”)
Disable diagnostic tools
It is recommended to disable it after using CPU profiling. This feature can be resource-intensive. After CPU analysis is enabled, it remains enabled for subsequent debugging sessions, so it can be displayed off when it is complete. If you do not need the functionality provided, you can save some resources by disabling the diagnostic tool during debugging.
To disable Diagnostics Tools, start a debug session and select Tools>; “Options” & gt; Enable Diagnostic Tools, then deselect the option.
Disable full solution analysis
Visual Studio performs analysis on the entire solution to provide a rich experience of the errors before the call is generated. This feature can be used to identify errors as quickly as possible. However, for very large solutions, this feature can be a significant memory resource hog. If you run out of memory or similar problems, you can disable this experience and release these resources. By default, Visual Basic enables this option, while C# disables it.
To disable Complete Solution Analysis, select Tools>; “Options” & gt;> “Text Editor” ”
Disable CodeLens
Visual Studio performs the Find All References task for each method displayed. Codelens provides functions such as inline display of reference numbers. Working in a separate process (for example, ServiceHub. RoslynCodeAnalysisService32). In very large solutions or resource-constrained systems, this feature can have a significant impact on performance, even if it is run at a lower priority. If you encounter high CPU or memory problems during this process (for example, when loading a large solution on a 4 GB machine), try disabling this feature to free up resources.
To disable CodeLens, select Tools>; “Options” & gt;> “Text Editor” ‘All Languages’> “Codelens”, then deselect the feature.
This feature is available in Visual Studio Professional and Visual Studio Enterprise.
Other tools and extensions
disable
Extensions are additional software components that are added to Visual Studio to provide new functionality or extend existing functionality. Expansion can often cause memory resource problems. If you encounter memory resource issues, try disabling the extension one at a time and see how this affects the schema or workflow.
to disable extension, please go to “tools” | “extension and update”, and then disable specific extensions.
Disable the XAML designer
By default, the XAML designer is enabled, but it only consumes resources when the.xaml file is opened. If you are using XAML files but do not want to use the designer feature, disable this feature to free up memory.
To disable the XAML designer, go to Tools>; “Options” & gt; “XAML Designer”> “Enable XAML Designer,” then deselect the option.
Delete the workload
You can use the Visual Studio installer to remove workloads that are no longer used. This action can skip packages and assemblies that are no longer used, thus optimizing startup and run time resource utilization.
Forced Garbage Collection
CLR uses a garbage collection memory management system. On this system, memory is sometimes consumed by objects that are no longer needed. This state is temporary and the garbage collector frees the memory based on its performance and resource usage heuristics. You can force the CLR to reclaim any unused memory by using hotkeys in Visual Studio. If there is a large amount of garbage waiting to be collected and garbage collection has been forced, you can see the memory utilization decrease for the devenv.exe process in the task manager. You rarely need to use this method. However, after a high-resource operation has been completed, such as a full build, debug session, or solution open event, this approach can help determine how much memory the process is actually using. Because Visual Studio is a hybrid (managed and native), native allocators and garbage collectors may sometimes compete for limited memory resources. This may help to force the garbage collector to run when memory usage is high.
To force garbage collection, use the hotkeys: Ctrl+Alt+Shift+F12, Ctrl+Alt+Shift+F12 (press twice).

The full coverage of the control system of TG pro

In some cases, it may be necessary to fully cover the system fan controls and use custom algorithms. You can use TG Pro by combining the power of the Auto Boost rule with the power of the overlay system. Keep in mind that when fan mode is set to Auto Boost, this completely replaces system fan control. If the fan speed is set too low, the system will not be able to increase or decrease the fan speed, causing the Mac to overheat. While this can be a very powerful feature, use at your own risk.

TG Pro Tutorial
To do this, first enable coverage for all fans. Depending on the Mac model you have, it will look like this:
for 2018 and 2019 Mac models (with T2 chips)
Applicable to all other Mac models
Now that TG Pro is fully covered, the Auto Boost rule must be added to increase fan speed as the temperature rises. This is very similar to the “Multiple automatic enhancement rule” section, but a rule must start at 0-100% of the maximum RPM (note: 0% is the minimum RPM). Otherwise, the fan will never be able to increase to its maximum speed, which is needed at very high temperatures.
here is a set of example rules:
fan speed is always at least 10%
if any sensor temperature is above 40°C,
fan speed will be 25%?If any sensor temperature is above 50 °C, the fan speed will be 50%
the fan speed will be 75% if any sensor temperature is above 60 °C
if any sensor temperature is above 70 °C, the fan speed will be 100%
The rules can vary, depending on whether the Mac is running on a battery or plugged in
To enable this feature, change the fan control mode to Auto Boost and TG Pro will adjust the fan speed to exactly how to set it according to the Auto Boost rule of the current power supply!
The above is the way to completely cover the system with TG Pro’s custom control function. Again, it should be emphasized that although this may be a very powerful function, use at your own risk!

C++ String case conversion and transform, tower, upper, usage

String case conversion is not provided in C++, but as I wrote today, there are many ways to do it.
Of course, you could have s[I]+32 or s[I]-32

#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>

using namespace std;

int main()
{
    string s = "Hello World";
    cout << s << endl;
    transform(s.begin(),s.end(),s.begin(),::toupper);//<span style="font-family:'Times New Roman';">::toupper</span>to<span style="font-family:'Times New Roman';">upp<span style="font-family:'Times New Roman';">er</span></span>
    cout << s << endl;
    transform(s.begin(),s.end(),s.begin(),::tolower);//<font face="'Times New Roman'">::t<span style="font-family:'Times New Roman';">olo<span style="font-family:'Times New Roman';">wer<span style="font-family:'Times New Roman';">使用</span></span></span></font><span style="font-family:'Times New Roman';"></span>to<span style="font-family:'Times New Roman';">lower</span>
    cout << s << endl;
    return 0;
}

Toupper and tolower are defined in C++ in STD and cctype, respectively

When defined in STD, the prototype is charT Toupper (charT C, Const Locale& loc);
While the transform function:
Applies an operation to each element of the specified scope.
The Transform function has two overloaded versions:

transform(first,last,result,op); // First is the first iterator of the container, last is the last iterator of the container, result is the container that holds the result, op is the unary function object or STURct, class to be operated on.

transform(first1,last1,first2,result,binary_op); // First1 is the first iterator of the first container, last1 is the last iterator of the first container, first2 is the first iterator of the second container, result is the container that holds the result, and binary_OP is the binary function object or STURct, class to be operated on
As above, the STD of toupper prototype as a binary function, so the use of STD: : toupper complains: unresolved overloaded function
But you can use it this way:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s = "Hello World";
    cout << s << endl;
    transform(s.begin(),s.end(),s.begin(),(int (*)(int))toupper);
    cout << s << endl;
    transform(s.begin(),s.end(),s.begin(),(int (*)(int))tolower);
    cout << s << endl;
    return 0;
}

Function pointer resolves

C++ string substr()

Common member function

< string>

std::string::substr

string substr (size_t pos = 0, size_t len = npos) const;

Produce substring
Returns a new one
A copy of the String object that is initialized to a substring of the String object.

The
substring is the part of the object that starts at character position pos and spans len characters (or up to the end of the string, whichever comes first).

parameter

pos

The position of the first character is copied as a substring.

this function returns an empty string if this is equal to the length of the string.

if this is greater than the length of the string, it will throw out_of_range.

note: the first character is represented as the value 0 (not 1).

len

The number of characters included in the subscript (if the string is short, as many characters as possible can be used as needed).

string :: non-profit value represents all characters up to the end of the string.

size_t is an unsigned integral type (the same as member type)
string::size_type).

The return value A
String Object with a substring of this object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// string::substr
#include <iostream>
#include <string>

int main ()
{
  std::string str="We think in generalities, but we live in details.";
                                           // (quoting Alfred N. Whitehead)

  std::string str2 = str.substr (3,5);     // "think"

  std::size_t pos = str.find("live");      // position of "live" in str

  std::string str3 = str.substr (pos);     // get from "live" to the end

  std::cout << str2 << ' ' << str3 << '\n';

  return 0;
}
 

Output:

think live in details.

C / C + + rounding function: round function

: : : : : : : : : : : : : : :

#include<iostream>
#include<cmath>
using namespace std;

int main(){
	cout<<"round(1.3) = "<<round(1.3)<<endl
		<<"round(1.5) = "<<round(1.5)<<endl
		<<"round(-1.3) = "<<round(-1.3)<<endl
		<<"round(-1.5) = "<<round(-1.5)<<endl;
	return 0;
}


this function takes the form of

double round(double d);

> > > > > > > > > > cmath>

C + + pauses the black window system (“pause”); (get ch(), getchar(), system (pause)’s connection and difference

In a c++ program, if it is a window, sometimes it will disappear with a flash. If you don’t want it to disappear, add:

system(“pause”);

Note: Do not add after the return statement, it will not be executed.

Analysis:

System () is a call to the system command;

pause pause command;

When run here, it will say “Press any key to continue…” or “Press any key to continue…” ;

In VS2008, can be called directly

VC 6.0, to add the following header file!

#include < stdlib.h>  
The

Supplement: http://bbs.csdn.net/topics/390231844

http://www.gidnetwork.com/b-61.html (the answer), 9/f,

1:

I don’t know why I often see people declare “void main” on CSDN

is not a standard entry point for C++

standard supports only two kinds of announcements

first type “int main”

int main(int argc, char *argv[]))

declares “void main” may have unexpected results

this doesn’t just apply to C++, C works as well

is this the textbook’s fault?Or is it the professors’ fault?

2:

do not use system(“pause”) to pause. Use STD ::cin. Get or getchar() instead.

why don’t you use system(“pause”)?

for two reasons

1: not portable
Two: it’s very expensive

where is it important?Let’s look at the process of system(“pause”)

1: pause your program

2: start the OS in the sub-process

3: finds the command to execute and allocates the memory for it

4: wait for input

5: recycle memory

6: end OS

7: continue your program

Getch () :
header file: conio. H
function purpose: read a character from the console, but not displayed on the screen
e.g. :
char ch; Or int ch;
getch (); Or ch = getch ();
with getch (); It waits for you to press any key before continuing with the following statement;
with ch = getch (); It waits for you to press any key, assigns the ASCII character to ch, and then executes the following statement.

getchar():
Extract characters from IO stream!
this function is declared in the stdio.h header file and used to include the stdio.h header file. Such as:
# include< stdio.h>
int getchar (void);
getch has the same basic functions as getchar, except that getch gets the key value directly from the keyboard and does not wait for the user to press enter. As soon as the user presses a key,
getch returns immediately. Getch returns the ASCII code entered by the user and returns -1 on error. The
getch function is commonly used in program debugging. During debugging, the relevant results are displayed in a critical position for viewing, and then the getch function is used to pause the program,
when any key is pressed after the program continues to run.

the first is that the two functions exist in different header files, this one basically you write #include< stdio.h> Getchar (), can accept a character, press enter to end, and display on the screen, and can clear forward just write
2. Getch (), receive a character, on the screen does not show
you write more, practice should be understood
Getchar () gets a character from the input device that is displayed on the screen, getch gets a character from the input device,
but the character is not displayed on the screen, for example:
#include < stdio.h>
int main()
{
printf(“%c”,getchar()); Suppose you get a character f from the keyboard here and press enter and you’ll see something like this
f
f
the first f is the f that you typed in, the second f is the f that printf gets
#include < stdio.h>

int main () {
printf (” % c “, getchar ());
}
suppose you enter an f and the result is
f this f is the printf output f
getchar is optimized,
getchar input character, until you press enter, then execute the code
getch without hitting enter
System (“pause”) can freeze the screen to observe the execution results of the program.
getch can not only pause the program
but also get a character
system(“pause”) is just a simple pause
the difference is the mechanism of action, although the effect looks the same. The
system return value is the result after you call the Shell command, and the getch() function will return the result provided by the function.
usually, the return value of Shell command may be unexpected and uncertain. Sometimes, it is impossible to judge whether the command
is executed successfully through the return value, which will have an impact on the program that conducts subsequent processing according to the return value. The return value of the function determines whether the
line is held successfully. But you don’t judge the return value at all, and you don’t process it, so you don’t have to worry about these differences.

How do you set, clear and toggle a single bit in C?

North Pole: http://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c
All kinds of answers. Haha… To learn!  
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

Setting a bit
Use the bitwise OR operator (|) to set a bit.

 number |= 1 << x;

That will set bit x.
Clearing a bit
Use the bitwise AND operator (&) to clear a bit.

 number &= ~(1 << x);

That will clear bit x. You must invert the bit string with the bitwise NOT operator (~), then AND it.
Toggling a bit
The XOR operator (^) can be used to toggle a bit.

 number ^= 1 << x;

That will toggle bit x.
Checking a bit
You didn’t ask for this but I might as well add it.
To check a bit, AND it with the bit you want to check:

 bit = number & (1 << x);

That will put the value of bit x into the variable bit.
===============================================================================================================================

Nobody mentioned the STL: std::bitset<N>.
Or the boost version: boost::dynamic_bitset.
No need to roll your own:

#include <bitset>
#include <iostream>

int main()
{
    std::bitset<5> x;

    x[1] = 1;
    x[2] = 0;
    // Note x[0-4]  valid

    std::cout << x << std::endl;
}

[Alpha:] > ./a.out
00010

Boost version allows a runtime sized bitset compared with STL compile time sized bitset.
===============================================================================================================================

The other option is to use bit fields:

struct bits {
    unsigned int a:1;
    unsigned int b:1;
    unsigned int c:1;
};

struct bits mybits;

defines a 3-bit field (actually, it’s three 1-bit felds). Bit operations now become a bit (haha) simpler:
To set or clear a bit:

mybits.b = 1;
mybits.c = 0;

To toggle a bit:

mybits.a = !mybits.a;
mybits.b = ~mybits.b;
mybits.c ^= 1;  /* all work */

Checking a bit:

if (mybits.c)

This only works with bits in fixed positions. Otherwise you have to resort to the bit-twiddling techniques described in previous posts.
===============================================================================================================================

It is sometimes worth using an enum to name the bits:

enum ThingFlags = {
  ThingMask  = 0x0000,
  ThingFlag0 = 1 << 0,
  ThingFlag1 = 1 << 1,
  ThingError = 1 << 8,
}

Then use the names later on. I.e. write

thingstate |= ThingFlag1;
thingstate &= ~ThingFlag0;
if (thing | ThingError) {...}

to set, clear and test. This way you hide the magic numbers from the rest of your code.
Other than that I endorse Jeremy’s solution.
===============================================================================================================================

I use macros defined in a header file to handle bit set and clear:

/* a=target variable, b=bit number to act upon 0-n */
#define BIT_SET(a,b) ((a) |= (1<<(b)))
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))
#define BIT_CHECK(a,b) ((a) & (1<<(b)))

/* x=target variable, y=mask */
#define BITMASK_SET(x,y) ((x) |= (y))
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))
#define BITMASK_FLIP(x,y) ((x) ^= (y))
#define BITMASK_CHECK(x,y) ((x) & (y))

===============================================================================================================================

From snip-c. zip’s bitops.how:

/*
**  Bit set, clear, and test operations
**
**  public domain snippet by Bob Stout
*/

typedef enum {ERROR = -1, FALSE, TRUE} LOGICAL;

#define BOOL(x) (!(!(x)))

#define BitSet(arg,posn) ((arg) | (1L << (posn)))
#define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
#define BitTst(arg,posn) BOOL((arg) & (1L << (posn)))
#define BitFlp(arg,posn) ((arg) ^ (1L << (posn)))

OK, let’s analyze things…
The common expression in all of these that you seem to be having problems with is “(1L << (posn))”. All this does is create a mask with a single bit on and which will work with any integer type. The “posn” argument specifies the position where you want the bit. If posn==0, then this expression will evaluate to:

    0000 0000 0000 0000 0000 0000 0000 0001 binary.

If posn==8, it will evaluate to

    0000 0000 0000 0000 0000 0001 0000 0000 binary.

In other words, it simply creates a field of 0’s with a 1 at the specified position. The only tricky part is in the BitClr() macro where we need to set a single 0 bit in a field of 1’s. This is accomplished by using the 1’s complement of the same expression as denoted by the tilde (~) operator.
Once the mask is created it’s applied to the argument just as you suggest, by use of the bitwise and (&), or (|), and xor (^) operators. Since the mask is of type long, the macros will work just as well on char’s, short’s, int’s, or long’s.
The bottom line is that this is a general solution to an entire class of problems. It is, of course, possible and even appropriate to rewrite the equivalent of any of these macros with explicit mask values every time you need one, but why do it?Remember, the macro substitution occurs in the preprocessor and so the generated code will reflect the fact that the values are considered constant by the compiler – i.e. it’s just as efficient to use the generalized macros as to “reinvent the wheel” every time you need to do bit manipulation.
Unconvinced?Here’s some test code – I used Watcom C with full optimization and without using _cdecl so the resulting disassembly would be as clean as possible:
—-[ TEST.C ]—————————————————————-

#define BOOL(x) (!(!(x)))

#define BitSet(arg,posn) ((arg) | (1L << (posn)))
#define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
#define BitTst(arg,posn) BOOL((arg) & (1L << (posn)))
#define BitFlp(arg,posn) ((arg) ^ (1L << (posn)))

int bitmanip(int word)
{
      word = BitSet(word, 2);
      word = BitSet(word, 7);
      word = BitClr(word, 3);
      word = BitFlp(word, 9);
      return word;
}

—-[ TEST. OUT (disassembled) ]———————————————–
Module: C:\BINK\tst.c Group: ‘DGROUP’ CONST,CONST2,_DATA,_BSS
Segment: TEXT BYTE 00000008 bytes
0000 0c 84 bitmanip or al,84H 0002 80 f4 02 xor ah,02H 0005 24 f7 and al,0f7H 0007 c3 ret
No disassembly errors
—-[ finis ]—————————————————————–

===============================================================================================================================
===============================================================================================================================

About the prompt: invalid use of incomplete type

In GCC or g++, when two classes need to refer to each other:
If a pointer to another class is declared in a.h file of one class, the class keyword can be used to declare the pointer first, instead of including the header file.
However, if an object defining a class or a specific member of a class is involved, the header file for that class must be included and declared without the class keyword.
Otherwise, a compilation error as shown in the title will occur!

If we want to define A pointer to class B in the header file of class A, and we want to define A pointer to class A in class B, then we can use class B in class A
Declare, without needing to contain a header file of class B,
But when we need to call A method of class B, we need to include its header file, which can then be included in the.cpP file of class A
Header file #include < B.h> , and the same is true in class B