Using OpenGL in C#: (9) Rewriting the C# OpenGL interface

C# OpenGL series, the first eight blogs have been completed in January 2018, basically talking about the technology involved in the C# OpenGL interface. At that time, I vowed to write a good blog, but I didn’t actually do it. Some things were not explained clearly, and some things were still wrong. In addition, the writing of the blog is not fluent, and it feels weird to read. I have said a lot in a long way, but I always feel that I can't understand it. Some readers commented that the article is very vivid, which is really a compliment. Regarding the issue of the source code, the previous source code was launched in a hurry, and it has not been fully tested at all. There are many bugs in it, and I can't bear to look directly at it. It was agreed to write more domos and auxiliary classes, but in the end I only did a little bit. In general, the source code of this OpenGL interface is poorly written, with various designs unreasonable, without considering future expansion, and the code has errors, and it feels like writing C# out of C (too deeply poisoned by C language) up). This time, I plan to rewrite the code and adopt new technology and design. At the time of writing this blog, the source code has been completed. Starting from this blog post, I will retell how to write the C# version of the OpenGL interface.

C# OpenGL interface source code and C# OpenGL programming examples can be downloaded from Baidu Netdisk: Link: https://pan.baidu.com/s/1dnIo1s-l6aqlE3IgaMJA5g 
Extraction code: wc0x

1. Digression

6 version) was released not long ago, and I had just finished my first year of graduate school. C# is also a short time. When I first started doing it, I didn't know if it could be done. At least when I wrote the first blog, I didn't know what to do. During the summer vacation, I didn’t go home. I stayed at school to do programming, thinking about whether I could go to Huawei in the future (it turned out that there was no door), and at the same time, I planned to write the source code in one month. Later facts showed that the whole project was carried out on and off for 5 months without even making a hair in one month! In the end, it was still in a hurry to go online, and even some known bugs were too late to change (or, I was too lazy to change). Of course, 5 months is not done every day, and it is also interspersed with graduate thesis. Seeing that all the students in the school are busy publishing papers, what EI, what SCI, I don't even know what I want to do. By January 2018, I had no clue about my thesis. Others were busy doing scientific research, and I was writing some code without doing my job. In the end, I was really anxious. Although I think I am a perfectionist, I can't stop the bad code from rushing online. So, in January 2018, I ended the writing of the code and the writing of the blog. The demo was not finished, and the auxiliary class was not finished. The source code was sent to CSDN, many users said yes, I felt guilty, some people said yes to such a bad thing, at that time, I was determined to take the time to clean up which codes. In fact, I found some of the bugs at the beginning, but I really didn't have time, and the graduation thesis was enough to make people worry about it. If the tutor finds out that I am not doing my job properly, I will be killed. In the second half of 2018, it was time to look for a job. I voted for Huawei, and was directly rejected. Then I voted for a small company in Tianjin that engages in 3D scanning, but was also despised. Later, I accepted an offer from a research institute, and the position was aircraft design. Related, think about how little programming will be used in the future, let alone OpenGL, the enthusiasm in my heart has basically dissipated. By May 2019, the graduation thesis defense was over. After a while, I remembered this incident again and wanted to take advantage of the free time before joining the job in July to correct the bugs in the original code. Later, I found out that the original code was just a piece of shit, and it couldn't be repaired, so I might as well write a new one. With previous experience, this time it was completed very quickly, and it took less than a month intermittently. The source code was completed in early July 2019. In order to complete it before joining the company, this time it was also in a hurry. The work was still not finished, and the code was still not fully tested. However, the new version of the code has a new design that looks more reasonable and has also modified the

2. Some changes and new technologies of the new version of C#OpenGL interface

(1) It allows multiple OpenGL rendering environments to be created at the same time, which can be switched when drawing, which provides convenience for multi-window drawing;

(2) OpenGL extended function pointer preloading, compared with the previous "load when used", may improve the operating efficiency;

(3) Reflection technology, which is mainly used in the preloading of OpenGL function pointers;

(4) Generic programming technology, which is mainly used in graphics operations, such as matrices and vectors;

(5) The winapi function and wgl function are disclosed to increase flexibility;

(6) The core mode and the compatibility mode are distinguished. The core mode only includes functions of version 4.6, and many functions of lower versions are abandoned, avoiding the embarrassment of misusing old functions when developing modern OpenGL, while the compatibility mode includes all new functions. Old version of the function.

3. Others

The source code of the new version encapsulates creating an OpenGL rendering environment, loading function pointers, and switching buffers into one class. In terms of code generation, I used to program in C language in the past, and a large part of the code was automatically generated. This time it seems that it is not so high-end, and the entire interface code generation is completed directly with the excel sheet, and the efficiency is not generally high.

4. Conclusion

The source code of the old version has many defects, and I really want to delete or replace it, but CSDN officials seem to refuse. What's even worse is that with more and more people downloading, the points required are also gradually increasing, and as resource contributors, they have no pricing power and no continuous income right! With a learning mentality, you can look at the source code of the old version . If you use it, it is recommended to use the new version , although there are also many bugs.

Previous: Using OpenGL in C#: (8) OpenGL extension functions

Guess you like

Origin blog.csdn.net/qq_28249373/article/details/97514956