gpt4 book ai didi

codeblocks - GLFW 和代码块

转载 作者:太空宇宙 更新时间:2023-11-04 14:10:20 25 4
gpt4 key购买 nike

我在使用 codeblocks 10.05 识别我机器上的 GLFW 库时遇到了一些困难。当我创建一个空项目并复制粘贴从这个 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 一起工作?谢谢

最佳答案

按照以下步骤操作。

  1. 首先从 here 下载 GLFW .
  2. 解压zip文件
  3. 从 include 文件夹中复制 glfw.h 文件并粘贴到文件夹“C:\Program Files\CodeBlocks\MinGW\include\GL”
  4. 从 lib_mingw 文件夹中复制所有文件(libglfw.a 和 libglfwdll.a)并粘贴到文件夹“C:\Program Files\CodeBlocks\MinGW\lib”
  5. 解压lib_mingw文件夹中的glfw.dll文件并粘贴在“C:\Windows\System32”文件夹中。如果您不想将它保留在 system32 中,那么您可以将它与您的项目 exe 文件一起保留。
  6. 现在在 code::blocks 中创建 GLFW 项目时,为 glfw 位置提供路径 C:\Program Files\CodeBlocks\MinGW"
  7. 如果您再次感到困惑,请前往 here一步一步的过程和每一步的图像。

关于codeblocks - GLFW 和代码块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14784156/

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