gpt4 book ai didi

codeblocks - GLFW 和代码块

转载 作者:行者123 更新时间:2023-12-03 23:30:33 34 4
gpt4 key购买 nike

我在识别我机器上的 GLFW 库的代码块 10.05 时遇到了一些困难。当我创建一个空项目并复制粘贴此 GLFW 教程中的代码时 >> http://content.gpwiki.org/index.php/GLFW:Tutorials:Basics

#include <stdlib.h>
#include <GL/glfw.h>

void Init(void);
void Shut_Down(int return_code);
void Main_Loop(void);
void Draw_Square(float red, float green, float blue);
void Draw(void);

float rotate_y = 0,
rotate_z = 0;
const float rotations_per_tick = .2;

int main(void)
{
Init();
Main_Loop();
Shut_Down(0);
}

void Init(void)
{
const int window_width = 800,
window_height = 600;

if (glfwInit() != GL_TRUE)
Shut_Down(1);
// 800 x 600, 16 bit color, no depth, alpha or stencil buffers, windowed
if (glfwOpenWindow(window_width, window_height, 5, 6, 5,
0, 0, 0, GLFW_WINDOW) != GL_TRUE)
Shut_Down(1);
glfwSetWindowTitle("The GLFW Window");

// set the projection matrix to a normal frustum with a max depth of 50
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float aspect_ratio = ((float)window_height) / window_width;
glFrustum(.5, -.5, -.5 * aspect_ratio, .5 * aspect_ratio, 1, 50);
glMatrixMode(GL_MODELVIEW);
}

void Shut_Down(int return_code)
{
glfwTerminate();
exit(return_code);
}

void Main_Loop(void)
{
// the time of the previous frame
double old_time = glfwGetTime();
// this just loops as long as the program runs
while(1)
{
// calculate time elapsed, and the amount by which stuff rotates
double current_time = glfwGetTime(),
delta_rotate = (current_time - old_time) * rotations_per_tick * 360;
old_time = current_time;
// escape to quit, arrow keys to rotate view
if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS)
break;
if (glfwGetKey(GLFW_KEY_LEFT) == GLFW_PRESS)
rotate_y += delta_rotate;
if (glfwGetKey(GLFW_KEY_RIGHT) == GLFW_PRESS)
rotate_y -= delta_rotate;
// z axis always rotates
rotate_z += delta_rotate;

// clear the buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw the figure
Draw();
// swap back and front buffers
glfwSwapBuffers();
}
}

void Draw_Square(float red, float green, float blue)
{
// Draws a square with a gradient color at coordinates 0, 10
glBegin(GL_QUADS);
{
glColor3f(red, green, blue);
glVertex2i(1, 11);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(-1, 11);
glColor3f(red * .5, green * .5, blue * .5);
glVertex2i(-1, 9);
glColor3f(red * .8, green * .8, blue * .8);
glVertex2i(1, 9);
}
glEnd();
}

void Draw(void)
{
// reset view matrix
glLoadIdentity();
// move view back a bit
glTranslatef(0, 0, -30);
// apply the current rotation
glRotatef(rotate_y, 0, 1, 0);
glRotatef(rotate_z, 0, 0, 1);
// by repeatedly rotating the view matrix during drawing, the
// squares end up in a circle
int i = 0, squares = 15;
float red = 0, blue = 1;
for (; i < squares; ++i){
glRotatef(360.0/squares, 0, 0, 1);
// colors change for each square
red += 1.0/12;
blue -= 1.0/12;
Draw_Square(red, .6, blue);
}
}

并使用代码块编译它会返回这个错误:
/home/user/Graphics/Project_2/test.c|27|undefined reference to `glfwInit'|
/home/user/Graphics/Project_2/test.c|30|undefined reference to `glfwOpenWindow'|
......
.....
....
...

但是当我创建一个简单的 *.c 文件并使用以下命令进行编译时:
gcc myprog.c -o myprog -lglfw -lGL -lpthread

它有效..如何使代码块与 GLFW 一起使用?
谢谢

最佳答案

请遵循以下程序。

  • 首先从 下载 GLFW here .
  • 解压压缩文件
  • 从包含文件夹中复制 glfw.h 文件并粘贴到文件夹“C:\Program Files\CodeBlocks\MinGW\include\GL”
  • 从 lib_mingw 文件夹中复制所有文件(libglfw.a 和 libglfwdll.a)
    并粘贴到文件夹“C:\Program Files\CodeBlocks\MinGW\lib”
  • 从解压缩文件的 lib_mingw 文件夹中提取 glfw.dll 文件并将其粘贴
    在“C:\Windows\System32”文件夹内。如果您不喜欢将其保存在 system32 中,则可以将其与项目 exe 文件一起保存。
  • 现在,在 code::blocks 中创建 GLFW 项目时,为 glfw 位置
  • 提供路径 C:\Program Files\CodeBlocks\MinGW"
  • 如果您再次感到困惑,请转到 here一步一步的过程,每一步的图像。
  • 关于codeblocks - GLFW 和代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7856648/

    34 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com