我在Xcode中有一个简单的OpenGL项目.
升级到4.5后,Xcode开始以一种奇怪的方式运行
在以下行中
#include <fstream.h>
Run Code Online (Sandbox Code Playgroud)
编译失败,出现以下错误消息:未找到词法或预处理器问题'fstream.h'文件.
用于在Xcode 4.2中成功编译的相同代码
将线路更改为
#include <c++/4.2.1/backward/fstream.h>
Run Code Online (Sandbox Code Playgroud)
修复了问题,但生成了其他一些编译错误.
我需要它的源代码gluCylinder和它调用的函数,所以我可以改变它们.我做了一些谷歌搜索,但我没有找到任何东西.
有人能指出我正确的方向吗?
我找不到任何有关如何加载PNG文件并将其用作纹理将其绑定到球体的不错的教程。是否有任何库函数可以执行此操作?我将如何将其绑定到球体上?我已经尝试过了,它没有用,没有错误,但是纹理没有加载到球体上。我用glutMainLoop()之前的特定文件调用LoadTexture。
这是我的文件加载代码:
GLuint LoadTexture( const char * filename, int width, int height )
{
GLuint texture;
unsigned char * data;
FILE * file;
//The following code will read in our PNG file
file = fopen( filename, "rb" );
if ( file == NULL ) return 0;
data = (unsigned char *)malloc( width * height * 3 );
fread( data, width * height * 3, 1, file );
fclose( file );
glGenTextures( 1, &texture ); //generate the texture with
glBindTexture( GL_TEXTURE_2D, …Run Code Online (Sandbox Code Playgroud) 好的,所以我有一个非常大的正方形(网格),我用三角形组成,然后应用高度图来碰撞它.我现在要做的是获得网格线.我已经找到了一种方法来做到这一点,但这会导致片段着色器中的33个if语句仅用于x,然后另外33个用于y.我被告知我可以使用我现在正在做的事情并稍微不同地实现它(使用一些GLSL函数)只需要1或2个if语句.这是我目前的代码(并非所有代码都已完成,但可以让您了解我在做什么.)
#version 330
uniform sampler2D texture;
in vec2 texCoord;
layout (location=0) out vec4 fragColour;
void main(void) {
vec4 newColor;
vec2 line = texCoord * 32; // makes texCoords easier to number (as divided by 32 in the C++array)
if(line.x > 0 && line.x < 0.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 1 && line.x < 1.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 2 && line.x < 2.9)
{
newColor = vec4(1.0,1.0,1.0,1.0);
}
else if(line.x > 3 …Run Code Online (Sandbox Code Playgroud) 我想用OpenGL编写代码,但我不想通过Windows API,这可能吗?如果是这样,那么一些关于如何做到这一点的教程的链接会很好.
好吧我在Windows 7上设置Visual Studio C++ 10所以我可以从本书"OpenGL superbible 5th edition"中运行示例程序,但是我有一些主要问题,在获取GLTools和freeglut的时候:
这是我如何设置一切到目前为止.........................
我上网后跟着这些步骤:
首先你要下载过剩或freeglut,然后解压缩它.
- 我从http://www.starstonesoftware.com/OpenGL/上的zip文件中得到了这个
在freeglut文件夹中应该有一个名为VisualStudio2008的文件夹,请进入此目的.
应该有一个名为freeglut的VS项目文件,运行它并在转换窗口出现时单击"完成".然后编译它,如果它完成它说无法启动,这没关系.
现在在同一个文件夹中应该有一个名为Debug的新文件夹,因为你刚刚编译了freeglut :).
在里面你会发现freeglut.dll.这需要分别进入你的system32文件夹或SysWOW64.
除此之外还有一个名为freeglut的文件,其类型将是Object File Library.这需要进入Visual Studio中的lib文件夹.
现在回到主要的freeglut文件夹.应该有一个名为Include的文件夹.在这个名为GL的文件夹和两个文件中.这些需要复制到Visual Studio中的Include文件夹中.
lib和Include文件夹位于VC文件夹中,该文件夹位于Visual Studio文件夹中,对我来说是Microsoft Visual Studio 10.0.
有:) .`
然后我按照以下步骤设置GLTools和freeglut:
这需要计算机上的管理员权限.
一世.将所有freeglut头文件(以.h结尾)复制到该文件夹:C:\ Program Files\Microsoft Visual Studio 10.0\VC\include\GL \
II.将所有GLTools头文件(以.h结尾)复制到C:\ Program Files\Microsoft Visual Studio 10.0\VC\include \
III.将所有freeglut和GLTools库文件(以.lib结尾)文件复制到C:\ Program Files\Microsoft Visual Studio 10.0\VC\lib \
IV.即使您已将GLTools.lib复制到lib文件夹中,您仍可能需要告诉VS2010在编译项目时使用GLTools.lib文件.从菜单选项View→Property Manager打开Property Manager(您需要一个打开的项目来执行此操作).VS IDE的左侧窗格将更改为显示属性管理器.您可以调整此大小以使其更具可读性.如果未显示完整列表,请展开项目,然后双击其中一个Microsoft.Cpp.Win32.user链接以打开用户属性对话框.在Property Manager中,选择Linker→Input,然后单击Additional Dependencies(见下文).在弹出的对话框中添加"GLTools.lib",我还为此添加了feeglut_static.lib!
好吧,所以最后这里是我想要运行的代码:
#include <GLTools.h> // OpenGL toolkit
#include <GLShaderManager.h> // Shader Manager Class
#ifdef __APPLE__
#include <glut/glut.h> // OS …Run Code Online (Sandbox Code Playgroud) OpenGl驱动程序是如何实现的?我试图了解如何在屏幕上绘制几何图元?在最低级别,opengl驱动程序如何在屏幕上绘制?
我看到有关OpenGL的文章比DirectX更好,微软真的只是试图让每个人都使用DirectX,即使它比较差,因此游戏几乎专门用于Windows和XBox,但自2006年撰写它今天仍然有用吗?
另外我知道有很多游戏都是用DirectX编写的,但有没有人有任何用OpenGL编写的流行游戏的例子?
我正在尝试制作地形网格,现在得到这样的东西:
GL.PushMatrix();
GL.Begin(BeginMode.TriangleStrip);
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 6; j++)
{
GL.Vertex2(0 + 50 * j, 0 + 50 * i);
GL.Vertex2(0 + 50 * j, 0 + 50 + 50 * i);
}
}
GL.End();
GL.PopMatrix();
Run Code Online (Sandbox Code Playgroud)
但它看起来不像是假设,它应该如何正确完成?
我正在为行星编写一个四叉树结构,当你远离四边形并接近它时,它会减少并增加细节.但是,我遇到了一些非常严重且烦人的错误.
我有两个预处理器定义的常量,当我将值更改为除32之外的任何值(例如16或64)时,确定Quad树的大小(QUAD_WIDTH和QUAD_HEIGHT)我得到一个蓝屏死机.我使用code :: blocks作为我的IDE,另外一件事:每当我尝试在code :: blocks中调试程序时,我也会得到一个蓝色的死亡屏幕(如果常量为32则无关紧要)
为什么会这样?我该如何解决呢?
PQuad.cpp
#include "..\include\PQuad.h"
#include "..\include\Color3.h"
#include <iostream>
#include <vector>
#include <cmath>
#include <GL/glew.h>
#include <GL/glu.h>
#include <GL/gl.h>
#define QUAD_WIDTH 32
#define QUAD_HEIGHT 32
#define NUM_OF_CHILDREN 4
#define MAX_DEPTH 4
PQuad::PQuad(FaceDirection face_direction, float planet_radius) {
this->built = false;
this->spherised = false;
this->face_direction = face_direction;
this->radius = planet_radius;
this->planet_centre = glm::vec3(0, 0, 0);
}
PQuad::~PQuad() {
}
std::vector<PQuad> PQuad::get_children() {
return children;
}
bool PQuad::get_built() {
return this->built;
}
int PQuad::get_depth() {
return this->depth;
} …Run Code Online (Sandbox Code Playgroud)