Text rendering method, system and device based on OpenGL SC and medium
Through the text rendering method based on OpenGL SC, the texture mapping and coordinate transformation are used to perform texture mapping and coordinate transformation, and the compatibility and portability of font rendering functions in the existing technology among different platforms is solved, and efficient font rendering across platforms is realized, reducing development complexity and authentication costs.
Patent Information
- Application Number
- CN202411971195.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-29
AI Technical Summary
In the prior art, the compatibility and portability of font rendering functions between different platforms are poor, resulting in increased development complexity and increased costs and risks in certification in security-critical areas.
Using the text rendering method based on OpenGL SC, the text rendering method is used to pre-generate character graphic data, and texture mapping and coordinate transformation are used to achieve cross-platform text rendering.
Cross-platform font rendering is realized, reducing development and maintenance complexity, and narrowing the scope of certification in security-critical areas, reducing costs and risks.
Smart Images

Figure CN119903814A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer user interface design, and in particular to a text rendering method, system, device and medium based on OpenGL SC. Background Art
[0002] Font rendering is an important area in computer graphics, which involves displaying characters or text on the screen in a visually pleasing and easily recognizable way. The quality of font rendering directly affects the user's overall experience and perception of the application or operating system. An excellent font rendering system can provide clear and smooth character display effects and support a variety of font styles and effects, such as anti-aliasing, font outlines, shadows, etc. At the same time, efficient font rendering can also reduce display latency, improve system responsiveness and user interaction experience.
[0003] At present, common font rendering technologies usually rely on font rendering engines provided by specific platforms or operating systems, such as DirectWrite on Windows, Core Text on macOS, and FreeType on Linux. These font rendering engines are tightly coupled with the underlying graphics library or operating system, providing high-quality font rendering capabilities. However, this platform-dependent implementation method results in poor compatibility and portability of font rendering functions across different platforms. Developers need to write specific code for different platforms, increasing the complexity of development and maintenance. In addition, when using third-party graphics libraries (such as OpenGL SC) for cross-platform development, font rendering functions are usually regarded as extended functions, requiring additional third-party library support or relying on the underlying graphics library of a specific platform. This requires that third-party libraries or platform-related codes be included in the certification scope when conducting certification in safety-critical areas, increasing the cost and risk of certification. Summary of the invention
[0004] To solve the above problems, the present invention provides a text rendering method, system, device and medium based on OpenGL SC.
[0005] The first aspect of the present invention discloses a text rendering method based on OpenGL SC, comprising:
[0006] receiving a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number;
[0007] According to the character library texture identifier, the target character serial number and the character graphic size parameter, searching for the character graphic data corresponding to each target character serial number from a pre-generated character graphic data set to obtain the target graphic data corresponding to the target character serial number;
[0008] Presetting the OpenGL SC graphics library according to the character library texture identifier;
[0009] Mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system;
[0010] Based on the OpenGL SC coordinates of the display position, the target graphic data corresponding to all the target character serial numbers are rendered in sequence using an OpenGL SC graphics library.
[0011] Furthermore, according to the character library texture identifier, the target character serial number and the character graphic size parameter, the step of searching for the target graphic data corresponding to each target character serial number from the pre-generated character graphic data set includes:
[0012] According to the character library texture identifier, searching for font library graphic data corresponding to the character library texture identifier from a character graphic data set;
[0013] According to each of the target character serial numbers and the character graphic size parameters, the data corresponding to each of the target character serial numbers in the font library graphic data is calculated as the target graphic data corresponding to the target character serial number.
[0014] Further, the step of presetting the OpenGL SC graphics library according to the character library texture identifier includes:
[0015] Set the OpenGL SC graphics library to 2D texture mode;
[0016] Setting the character library texture identifier as a 2D texture target of the OpenGL SC graphics library;
[0017] Sets linear interpolation as the 2D texture filtering mode for the OpenGL SC graphics library.
[0018] Furthermore, the step of mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system includes:
[0019] According to the coordinate range of the OpenGL SC graphics library and the size information of the display interface, the coordinates of the display position on the display interface are normalized to obtain the OpenGL SC coordinates of the display position.
[0020] Furthermore, according to the coordinate range of the OpenGL SC graphics library and the size information of the display interface, the coordinates of the display position on the display interface are normalized to obtain the OpenGL SC coordinates of the display position, including:
[0021] The coordinates of the display position on the display interface are normalized according to the following formula:
[0022]
[0023]
[0024] Among them, x represents the horizontal coordinate of the display position relative to the display interface, y represents the vertical coordinate of the display position relative to the display interface, openGL_x represents the horizontal coordinate of the display position in the OpenGL SC coordinate system, openGL_y represents the vertical coordinate of the display position in the OpenGL SC coordinate system, w represents the width of the display interface, and h represents the height of the display interface.
[0025] Furthermore, the text rendering request further includes: a character alignment mode and a character display size, wherein the character display size indicates a size of a rendering area of a target graphic data corresponding to the display terminal;
[0026] And, based on the OpenGL SC coordinates of the display position, the step of rendering the target graphic data corresponding to all the target character serial numbers using the OpenGL SC graphics library in sequence comprises:
[0027] Calculating the character mapping size of the target graphic data in the OpenGL SC graphics library coordinate system according to the character display size;
[0028] Calculate the rendering width of the target graphic data corresponding to all target character numbers in the OpenGL SC graphics library coordinate system according to the number of the target character numbers and the character mapping size;
[0029] Determine the rendering start position according to the rendering width, the OpenGL SC coordinates of the display position and the character alignment mode; wherein the rendering start position is the rendering position of the target graphic data corresponding to the first target character sequence number in the OpenGL SC graphics library coordinate system;
[0030] Calculate the character position information of the target graphic data corresponding to each target character sequence number in the OpenGL SC graphics library coordinate system according to the rendering start position and the order of each target character sequence number in the text rendering request;
[0031] For each target character sequence number, character rendering is performed using the OpenGL SC graphics library according to the corresponding character position information and target graphic data.
[0032] Furthermore, the character graphic data set is pre-generated in the following manner:
[0033] Acquire a plurality of font library graphic data; wherein the font library graphic data includes a plurality of the character graphic data;
[0034] Apply to the OpenGL SC graphics library for a corresponding texture identifier for each font library graphic data as a character library texture identifier;
[0035] The font library graphic data is bound to the corresponding character library texture identifier to obtain a character graphic data set.
[0036] The second aspect of the present invention discloses a text rendering system based on OpenGL SC, comprising:
[0037] A receiving module, configured to receive a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number;
[0038] A search module, for searching for character graphic data corresponding to each target character number from a pre-generated character graphic data set according to the character library texture identifier, the target character number and the character graphic size parameter, to obtain the target graphic data corresponding to the target character number;
[0039] A setting module, used for presetting the OpenGL SC graphics library according to the character library texture identifier;
[0040] A mapping module, used for mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system;
[0041] The rendering module is used to render the target graphic data corresponding to all the target character serial numbers in sequence using the OpenGL SC graphics library based on the OpenGL SC coordinates of the display position.
[0042] The third aspect of the present invention discloses an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and is characterized in that when the processor executes the computer program, it implements the steps of any OpenGL SC-based text rendering method disclosed in the first aspect of the present invention.
[0043] The fourth aspect of the present invention discloses a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of any OpenGLSC-based text rendering method disclosed in the first aspect of the present invention.
[0044] The present invention proposes a text rendering method based on OpenGL SC, aiming to solve the cross-platform compatibility problem of font rendering in the prior art and provide a universal and efficient font rendering solution. The method utilizes the basic drawing function provided by the OpenGL SC graphics library, and converts character rendering into a process of texture mapping and coordinate transformation by pre-generating character graphics data. The method does not rely on the font rendering engine of a specific platform or operating system, and has good cross-platform support. At the same time, since the standard OpenGL SC graphics library is used, the method can be easily integrated into various applications, reducing the complexity of development and maintenance. When conducting certification in safety-critical areas, since it does not rely on third-party libraries or platform-related codes, the scope of certification can be greatly narrowed, reducing the cost and risk of certification. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0046] Figure 1 It is a flowchart of a text rendering method based on OpenGL SC disclosed in an embodiment of the present invention;
[0047] Figure 2 It is a structural schematic diagram of a text rendering system based on OpenGL SC disclosed in an embodiment of the present invention;
[0048] Figure 3 It is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. DETAILED DESCRIPTION
[0049] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0050] The terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, device, or product end including a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units inherent to these processes, methods, products, or ends.
[0051] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present invention. The appearance of the phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0052] See also Figure 1 As shown, Figure 1 FIG. 1 is a flowchart of a text rendering method based on OpenGL SC disclosed in an embodiment of the present invention. Figure 1 As shown, the text rendering method based on OpenGL SC may include the following operations:
[0053] S101, receiving a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number;
[0054] In this optional embodiment, the character library texture identifier is used to identify the font library used. OpenGL SC is a cross-platform, high-performance graphics programming interface that provides a set of standard, feature-rich graphics drawing and rendering functions that can be used to develop various 2D and 3D graphics applications. The texture of OpenGL SC is a technology that maps image data to the surface of geometric figures. By associating the texture image with the vertices of the geometric figures and controlling the mapping method of the image on the surface of the geometric figures through texture coordinates, rich surface details and realism can be provided for simple geometric figures. The character library texture identifier refers to the texture identifier of the character library's graphic data in OpenGL SC.
[0055] The character graphic size parameter is used to specify the size of the character graphic. The character graphic size parameter can be used to control the size of the rendered characters to meet different display requirements. The character graphic size parameter is usually expressed in pixels, indicating the width and height of the character graphic.
[0056] The display position is used to specify the target position of text rendering, that is, the starting coordinates of the text on the display interface. The display position parameters can be used to control the display position of the text and achieve flexible text layout. The display position is usually expressed in the coordinate system of the display interface, such as the horizontal and vertical coordinates in pixels. Target character sequence number: used to specify the characters to be rendered, that is, the text content to be displayed.
[0057] The target character serial number can be one or more, indicating the number or index of the character to be rendered in the font library. Through the target character serial number, the specified character can be selectively rendered as needed to achieve flexible text content control.
[0058] S102, searching for character graphic data corresponding to each target character number from a pre-generated character graphic data set according to the character library texture identifier, the target character number and the character graphic size parameter, to obtain the target graphic data corresponding to the target character number;
[0059] In an optional embodiment, the step of searching for target graphic data corresponding to each target character sequence number from a pre-generated character graphic data set according to the character library texture identifier, the target character sequence number and the character graphic size parameter comprises:
[0060] According to the character library texture identifier, searching for font library graphic data corresponding to the character library texture identifier from a character graphic data set;
[0061] According to each of the target character serial numbers and the character graphic size parameters, the data corresponding to each of the target character serial numbers in the font library graphic data is calculated as the target graphic data corresponding to the target character serial number.
[0062] For example: the character library texture identifier in the text rendering request is Arial_12, which points to all character graphic data belonging to the Arial font in the character graphic data set. The target character serial numbers in the text rendering request are 4 and 20, and the character graphic size parameter is 24x24 (that is, the size of the character rendered on the display interface is 24x24 pixels). Each character graphic data corresponds to a 32-bit color depth, 8 bits for each color channel, and 8 bits for the transparency channel. Then each pixel requires 4 bytes of storage space, and the number of bytes corresponding to each character graphic data is: 24×24×4=2304 bytes.
[0063] The starting address of all character graphic data corresponding to Arial_12 is besaAddress, and the address range of the character graphic data with the target character number 4 in the memory is:
[0064] besaAddress+4×2304~besaAddress+5×2304-1;
[0065] The address range of the character graphic data with the target character number 20 in the memory is:
[0066] besaAddress+20×2304~besaAddress+20×2304-1;
[0067] It can be seen that this optional embodiment fully considers the flexibility and customizability of the character library, and the user can design and generate a character library containing specific character graphic data according to their own needs. Through the character library texture identification and the target character serial number, the required character graphic data can be quickly located, avoiding unnecessary storage and calculation overhead, and improving the search efficiency of character graphic data. At the same time, the introduction of character graphic size parameters allows the character graphic data to adapt to different rendering sizes, providing more flexible character display control. This flexible character library design and efficient character graphic data search method can meet various text rendering requirements and improve the adaptability and customizability of text rendering.
[0068] S103, presetting the OpenGL SC graphics library according to the character library texture identifier;
[0069] In an optional embodiment, the step of presetting the OpenGL SC graphics library according to the character library texture identifier includes:
[0070] Set the OpenGL SC graphics library to 2D texture mode;
[0071] Setting the character library texture identifier as a 2D texture target of the OpenGL SC graphics library;
[0072] Sets linear interpolation as the 2D texture filtering mode for the OpenGL SC graphics library.
[0073] The OpenGL SC graphics library provides a variety of texture modes for processing different types of texture data. Among them, the 2D texture mode is used to process image data on a two-dimensional plane. In the 2D texture mode, the image data is organized into a two-dimensional array, and each array element represents a pixel on the image. By applying 2D textures to the surface of geometric figures, rich texture mapping effects such as maps, labels, etc. can be achieved. Setting the OpenGL SC graphics library to 2D texture mode means that subsequent texture operations will be performed on 2D textures so that character graphics data can be used in text rendering.
[0074] In OpenGL SC, a texture target is an identifier used to identify a specific texture object. By setting the character library texture identifier as the 2D texture target of the OpenGL SC graphics library, all character graphics data corresponding to the character library texture identifier can be associated with the texture object of OpenGL SC. In this way, in subsequent rendering operations, the corresponding character graphics data can be accessed and used by referencing the texture target.
[0075] Texture filtering is a technique used to handle texture scaling and interpolation. When the resolution of the texture image does not match the resolution of the rendering target, the texture needs to be scaled or interpolated to meet the rendering requirements. Linear interpolation generates new pixel color values by linearly interpolating the color values of adjacent pixels. Compared with nearest neighbor filtering, linear interpolation can produce smoother and more natural texture effects, reducing aliasing and distortion when scaling. Setting linear interpolation as the 2D texture filtering mode of the OpenGL SC graphics library means that in text rendering, when character graphic data needs to be scaled, it will be processed using linear interpolation to obtain high-quality character display effects.
[0076] S104, mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system;
[0077] In an optional embodiment, the step of mapping the coordinates of the display position on the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system includes:
[0078] According to the coordinate range of the OpenGL SC graphics library and the size information of the display interface, the coordinates of the display position on the display interface are normalized to obtain the OpenGL SC coordinates of the display position.
[0079] In a further optional embodiment, the coordinates of the display position on the display interface are normalized according to the coordinate range of the OpenGL SC graphics library and the size information of the display interface, and the step of obtaining the OpenGL SC coordinates of the display position includes:
[0080] The coordinates of the display position on the display interface are normalized according to the following formula:
[0081]
[0082] Wherein, x represents the horizontal coordinate of the display position relative to the display interface, y represents the vertical coordinate of the display position relative to the display interface, openGL_x represents the horizontal coordinate of the display position in the OpenGL SC coordinate system, openGL_y represents the vertical coordinate of the display position in the OpenGL SC coordinate system, w represents the width of the display interface, and h represents the height of the display interface. In this embodiment, the coordinates of the display interface take the upper left corner of the display interface as the origin. Those skilled in the art can derive specific methods for normalizing the coordinates of the display position in the display interface in various coordinate systems of the display interface without creative analysis, and the present invention will not repeat them.
[0083] S105 . Based on the OpenGL SC coordinates of the display position, render the target graphic data corresponding to all the target character serial numbers in sequence using an OpenGL SC graphics library.
[0084] In an optional embodiment, the text rendering request further includes: a character alignment mode and a character display size, wherein the character display size indicates the size of a rendering area of a target graphic data corresponding to the display terminal;
[0085] And, based on the OpenGL SC coordinates of the display position, the step of rendering the target graphic data corresponding to all the target character serial numbers using the OpenGL SC graphics library in sequence comprises:
[0086] Calculating the character mapping size of the target graphic data in the OpenGL SC graphics library coordinate system according to the character display size;
[0087] Calculate the rendering width of the target graphic data corresponding to all target character numbers in the OpenGL SC graphics library coordinate system according to the number of the target character numbers and the character mapping size;
[0088] Determine the rendering start position according to the rendering width, the OpenGL SC coordinates of the display position and the character alignment mode; wherein the rendering start position is the rendering position of the target graphic data corresponding to the first target character sequence number in the OpenGL SC graphics library coordinate system;
[0089] Calculate the character position information of the target graphic data corresponding to each target character sequence number in the OpenGL SC graphics library coordinate system according to the rendering start position and the order of each target character sequence number in the text rendering request;
[0090] For each target character sequence number, character rendering is performed using the OpenGL SC graphics library according to the corresponding character position information and target graphic data.
[0091] For example, the text rendering request carries five target character numbers, and the rendering width of the target graphic data corresponding to each target character number in the OpenGL SC graphics library coordinate system is 0.1. The character display size is based on the size of the display interface coordinate system. The method for normalizing the character display size is the same as the method in the aforementioned embodiment, and will not be repeated here.
[0092] The rendering width of the target graphic data corresponding to the five target character numbers in the OpenGL SC graphics library coordinate system is 0.5, and the OpenGL SC coordinate of the display position is assumed to be -0.9, then the horizontal coordinate of the rendering start position is Then the horizontal coordinate of the character position information of the target graphic data corresponding to the second target character serial number in the OpenGL SC graphics library coordinate system is -0.2+0.1=-0.1, and the horizontal coordinate of the character position information of the target graphic data corresponding to the third target character serial number in the OpenGL SC graphics library coordinate system is -0.2+0.1×2=0, and so on, to obtain the horizontal coordinates of the character position information of the target graphic data corresponding to the five target character serial numbers in the OpenGL SC graphics library coordinate system, and the vertical coordinate in the character position information is the vertical coordinate in the OpenGL SC coordinate of the display position.
[0093] In an optional embodiment, the character graphic data set is pre-generated in the following manner:
[0094] Acquire a plurality of font library graphic data; wherein the font library graphic data includes a plurality of the character graphic data;
[0095] Apply to the OpenGL SC graphics library for a corresponding texture identifier for each font library graphic data as a character library texture identifier;
[0096] The font library graphic data is bound to the corresponding character library texture identifier to obtain a character graphic data set.
[0097] See also Figure 2 As shown, Figure 2 FIG. 1 is a schematic diagram of a text rendering system based on OpenGL SC disclosed in an embodiment of the present invention. Figure 2 As shown, the text rendering system includes:
[0098] The receiving module 201 is used to receive a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number;
[0099] A search module 202 is used to search for character graphic data corresponding to each target character number from a pre-generated character graphic data set according to the character library texture identifier, the target character number and the character graphic size parameter, and obtain the target graphic data corresponding to the target character number;
[0100] A setting module 203, used for presetting the OpenGL SC graphics library according to the character library texture identifier;
[0101] A mapping module 204, used for mapping the coordinates of the display position in the display interface into OpenGL SC coordinates in an OpenGL SC graphics library coordinate system;
[0102] The rendering module 205 is used to render the target graphic data corresponding to all the target character serial numbers in sequence using the OpenGL SC graphics library based on the OpenGL SC coordinates of the display position.
[0103] For the specific limitations of the text rendering system based on OpenGL SC, please refer to the limitations of the text rendering method based on OpenGL SC above, which will not be repeated here. Each module in the above-mentioned text rendering system based on OpenGL SC can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the electronic device in hardware format, or can be stored in the memory of the electronic device in software format, so that the processor can call the corresponding operations of the above modules.
[0104] It should be noted that, in order to highlight the innovative part of the present invention, the present embodiment does not introduce modules that are not closely related to solving the technical problem proposed by the present invention, but this does not mean that there are no other modules in the present embodiment.
[0105] like Figure 3As shown, the electronic device 1 provided by the present invention may include a memory 12, a processor 13 and a bus, and may also include a computer program stored in the memory 12 and executable on the processor 13, such as a text rendering program based on OpenGLSC.
[0106] Among them, the memory 12 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, mobile hard disk, multimedia card, card-type memory (for example: SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the electronic device 1, such as a mobile hard disk of the electronic device 1. In other embodiments, the memory 12 can also be an external storage device of the electronic device 1, such as a plug-in mobile hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 1. Further, the memory 12 can also include both an internal storage unit of the electronic device 1 and an external storage device. The memory 12 can not only be used to store application software and various types of data installed in the electronic device 1, such as text rendering code based on OpenGL SC, etc., but also can be used to temporarily store data that has been output or is to be output.
[0107] In some embodiments, the processor 13 may be composed of an integrated circuit, for example, a single packaged integrated circuit, or a plurality of packaged integrated circuits with the same or different functions, including one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and combinations of various control chips. The processor 13 is the control core (Control Unit) of the electronic device 1, and uses various interfaces and lines to connect various components of the entire electronic device 1, and executes or executes programs or modules (such as text rendering programs based on OpenGL SC, etc.) stored in the memory 12, and calls data stored in the memory 12 to execute various functions of the electronic device 1 and process data.
[0108] The processor 13 executes the operating system and various installed application programs of the electronic device 1. The processor 13 executes the application programs to implement the steps in the above-mentioned text rendering method based on OpenGL SC.
[0109] Exemplarily, the computer program may be divided into one or more modules, which are stored in the memory 12 and executed by the processor 13 to complete the present application. The one or more modules may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program in the electronic device 1. For example, the computer program may be divided into a receiving module 201, a search module 202, a setting module 203, a mapping module 204, and a rendering module 205.
[0110] The above-mentioned integrated unit implemented in the form of a software function module can be stored in a computer-readable storage medium, and the storage medium can be non-volatile or volatile. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a computer device, or a network device, etc.) or a processor to perform part of the functions of the text rendering method based on OpenGL SC described in various embodiments of the present application.
[0111] In summary, the text rendering method, system, device and medium based on OpenGL SC disclosed in the present invention do not rely on the font rendering engine of a specific platform or operating system and have good cross-platform support. At the same time, due to the use of the standard OpenGL SC graphics library, the method can be easily integrated into various applications, reducing the complexity of development and maintenance. When performing certification in security-critical areas, since it does not rely on third-party libraries or platform-related codes, the scope of certification can be greatly reduced, reducing the cost and risk of certification. Therefore, the present invention effectively overcomes the various shortcomings in the prior art and has a high industrial utilization value.
[0112] The above embodiments are merely illustrative of the principles and effects of the present invention, and are not intended to limit the present invention. Anyone familiar with the art may modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by a person of ordinary skill in the art without departing from the spirit and technical concept disclosed by the present invention shall still be covered by the claims of the present invention.
Claims
1. A text rendering method based on OpenGL SC, characterized in that: The method comprises: receiving a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number; According to the character library texture identifier, the target character serial number and the character graphic size parameter, searching for the character graphic data corresponding to each target character serial number from a pre-generated character graphic data set to obtain the target graphic data corresponding to the target character serial number; Presetting the OpenGL SC graphics library according to the character library texture identifier; Mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system; Based on the OpenGL SC coordinates of the display position, the target graphic data corresponding to all the target character serial numbers are rendered in sequence using an OpenGL SC graphics library.
2. The text rendering method based on OpenGL SC according to claim 1, characterized in that: The step of searching the target graphic data corresponding to each target character sequence number from the pre-generated character graphic data set according to the character library texture identifier, the target character sequence number and the character graphic size parameter comprises: According to the character library texture identifier, searching for font library graphic data corresponding to the character library texture identifier from a character graphic data set; According to each of the target character serial numbers and the character graphic size parameters, the data corresponding to each of the target character serial numbers in the font library graphic data is calculated as the target graphic data corresponding to the target character serial number.
3. The text rendering method based on OpenGL SC according to claim 1, characterized in that: According to the character library texture identifier, the step of presetting the OpenGL SC graphics library includes: Set the OpenGL SC graphics library to 2D texture mode; Setting the character library texture identifier as a 2D texture target of the OpenGL SC graphics library; Sets linear interpolation as the 2D texture filtering mode for the OpenGL SC graphics library.
4. The text rendering method based on OpenGL SC according to claim 1, characterized in that: The step of mapping the coordinates of the display position on the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system includes: According to the coordinate range of the OpenGL SC graphics library and the size information of the display interface, the coordinates of the display position on the display interface are normalized to obtain the OpenGL SC coordinates of the display position.
5. The text rendering method based on OpenGL SC according to claim 4, characterized in that: The step of normalizing the coordinates of the display position on the display interface according to the coordinate range of the OpenGL SC graphics library and the size information of the display interface to obtain the OpenGL SC coordinates of the display position includes: The coordinates of the display position on the display interface are normalized according to the following formula: Among them, x represents the horizontal coordinate of the display position relative to the display interface, y represents the vertical coordinate of the display position relative to the display interface, openGL_x represents the horizontal coordinate of the display position in the OpenGL SC coordinate system, openGL_y represents the vertical coordinate of the display position in the OpenGL SC coordinate system, w represents the width of the display interface, and h represents the height of the display interface.
6. The text rendering method based on OpenGL SC according to claim 1, characterized in that: The text rendering request also includes: a character alignment mode and a character display size, wherein the character display size indicates the size of a rendering area of a target graphic data corresponding to the display terminal; And, based on the OpenGL SC coordinates of the display position, the step of rendering the target graphic data corresponding to all the target character serial numbers using the OpenGL SC graphics library in sequence comprises: Calculating the character mapping size of the target graphic data in the OpenGL SC graphics library coordinate system according to the character display size; Calculate the rendering width of the target graphic data corresponding to all target character numbers in the OpenGL SC graphics library coordinate system according to the number of the target character numbers and the character mapping size; Determine the rendering start position according to the rendering width, the OpenGL SC coordinates of the display position and the character alignment mode; wherein the rendering start position is the rendering position of the target graphic data corresponding to the first target character sequence number in the OpenGL SC graphics library coordinate system; Calculate the character position information of the target graphic data corresponding to each target character sequence number in the OpenGL SC graphics library coordinate system according to the rendering start position and the order of each target character sequence number in the text rendering request; For each target character serial number, character rendering is performed using the OpenGLSC graphics library according to its corresponding character position information and target graphic data.
7. The text rendering method based on OpenGL SC according to claim 1, characterized in that: The character graphic data set is pre-generated in the following manner: Acquire a plurality of font library graphic data; wherein the font library graphic data includes a plurality of the character graphic data; Apply to the OpenGL SC graphics library for a corresponding texture identifier for each font library graphic data as a character library texture identifier; The font library graphic data is bound to the corresponding character library texture identifier to obtain a character graphic data set.
8. A text rendering system based on OpenGL SC, characterized in that: include: A receiving module, configured to receive a text rendering request, wherein the text rendering request includes a character library texture identifier, a character graphic size parameter, a display position, and at least one target character sequence number; A search module, for searching for character graphic data corresponding to each target character number from a pre-generated character graphic data set according to the character library texture identifier, the target character number and the character graphic size parameter, to obtain the target graphic data corresponding to the target character number; A setting module, used for presetting the OpenGL SC graphics library according to the character library texture identifier; A mapping module, used for mapping the coordinates of the display position in the display interface to OpenGL SC coordinates in the OpenGL SC graphics library coordinate system; The rendering module is used to render the target graphic data corresponding to all the target character serial numbers in sequence using the OpenGL SC graphics library based on the OpenGL SC coordinates of the display position.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the text rendering method based on OpenGL SC are implemented as described in any one of claims 1 to 7.
10. A storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the text rendering method based on OpenGL SC as claimed in any one of claims 1 to 7 are implemented.