Frozen5293's blog Frozen5293's blog
首页
  • 游戏开发
  • 博客相关
  • 技术问题
  • 分类
  • 标签
  • 归档
  • 友情链接
关于
GitHub (opens new window)

Frozen5293

刀剑钺戟摧狂浪,山河草木岁众生
首页
  • 游戏开发
  • 博客相关
  • 技术问题
  • 分类
  • 标签
  • 归档
  • 友情链接
关于
GitHub (opens new window)
  • 11

frozen5293
2023-08-15
随笔

11

#dasd

#include<Windows.h>
#include <glad/glad.h>
#include <iostream>
#include <GLFW/glfw3.h>

typedef HGLRC (WINAPI * PFNWGLCREATECONTEXT)(HDC);
PFNWGLCREATECONTEXT wglCreateContextPtr;

typedef BOOL (WINAPI * PFNWGLMAKECURRENT)(HDC, HGLRC);
PFNWGLMAKECURRENT wglMakeCurrentPtr;

///显示在屏幕上

int main(){
    HMODULE hOpenGL = LoadLibrary("OpenGL32.dll");
    wglCreateContextPtr = (PFNWGLCREATECONTEXT)GetProcAddress(hOpenGL, "wglCreateContext");
    wglMakeCurrentPtr = (PFNWGLMAKECURRENT)GetProcAddress(hOpenGL, "wglMakeCurrent");
    // 像素表格描述器
    PIXELFORMATDESCRIPTOR pfd;
    pfd.nSize=40;
    pfd.nVersion=1;
    //
    pfd.dwFlags=PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
    pfd.iPixelType=PFD_TYPE_RGBA;
    pfd.cColorBits=0;
    //
    pfd.cRedBits=0;
    pfd.cRedShift=0;
    pfd.cGreenBits=0;
    pfd.cGreenShift=0;
    pfd.cBlueBits=0;
    pfd.cBlueShift=0;
    pfd.cAlphaBits=0;
    pfd.cAlphaShift=0;
    //
    pfd.cAccumBits=0;
    pfd.cAccumRedBits=0;
    pfd.cAccumBlueBits=0;
    pfd.cAccumGreenBits=0;
    pfd.cAccumAlphaBits=0;
    //
    pfd.cDepthBits=0;
    pfd.cStencilBits=0;
    pfd.cAuxBuffers=0;
    pfd.iLayerType=PFD_MAIN_PLANE;
    pfd.bReserved=0;
    pfd.dwLayerMask=0;
    pfd.dwVisibleMask=0;
    pfd.dwDamageMask=0;

    // glfwInit();
    // glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
    // GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL", NULL, NULL);
    // glfwMakeContextCurrent(window);
    // 获取设备屏幕
    HDC hdc=GetDC(NULL);
    int pixelFormat=ChoosePixelFormat(hdc,&pfd);
    SetPixelFormat(hdc,pixelFormat,&pfd);
    HGLRC hglrc=wglCreateContextPtr(hdc);
    wglMakeCurrentPtr(hdc,hglrc);

    // 绘制
    if (!gladLoadGL()) {
        std::cout << "GLAD failed to load" << std::endl;
        return -1;
    }
    int i=1;
    while (i<100){
        ++i;
        glViewport(0,0,800,800);
        glColor3f(1.0f,0.0f,0.0f);
        glBegin(GL_TRIANGLES);
        glVertex2f(-0.5f,-0.5f);
        glVertex2f(0.0f,0.5f);
        glVertex2f(0.5f,-0.5);
        glEnd();
        glFlush();
    }
    std::cout<<"normal end"<<std::endl;
    // glfwTerminate();
    return 0;
    
}



//     glad
//     int i =0;
//     while(i<1000){
//         ++i;
//         glDrawArrays( GL_LINES, 0, 2 );
//     }
//     return 0;
// }


// #include <glad/glad.h>
// #include <Windows.h>
// #include <iostream>

// int main(){
    
//     if (!gladLoadGL()) {
//         std::cout << "GLAD failed to load" << std::endl;
//         return -1;
//     }

//     // 绘制三角形
//     float vertices[] = {
//         -0.5f, -0.5f, 0.0f,
//         0.5f, -0.5f, 0.0f,
//         0.0f,  0.5f, 0.0f
//     };

//     unsigned int VBO, VAO;
//     glGenVertexArrays(1, &VAO);
//     glGenBuffers(1, &VBO);

//     glBindVertexArray(VAO);
//     glBindBuffer(GL_ARRAY_BUFFER, VBO);
//     glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
//     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
//     glEnableVertexAttribArray(0);

//     glDrawArrays(GL_TRIANGLES, 0, 3);

//     glBindBuffer(GL_ARRAY_BUFFER, 0);
//     glBindVertexArray(0);

//     glDeleteVertexArrays(1, &VAO);
//     glDeleteBuffers(1, &VBO);

//     // 在屏幕上绘制
//     glFinish();
//     HDC hdc = GetDC(NULL);
//     glReadBuffer(GL_FRONT);
//     glDrawBuffer(GL_BACK);
//     glBlitFramebuffer(0, 0, 640, 480, 0, 0, 640, 480, GL_COLOR_BUFFER_BIT, GL_NEAREST);
//     SwapBuffers(hdc);
//     ReleaseDC(NULL, hdc);
//     std::cout << "finish" << std::endl;
//     return 0;
// }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
编辑 (opens new window)
上次更新: 2024/04/16, 00:35:21
最近更新
01
Rust序列化函数
04-29
02
Rust错误处理
04-29
03
1
04-29
更多文章>
Theme by Vdoing | Copyright © 2019-2024 Frozen5293 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式