我有一个全局指定作为指向我的窗口的指针,如下所示:
globals.cpp & globals.h 具有:
#include <SFML/Graphics.hpp>
sf::RenderWindow* window
Run Code Online (Sandbox Code Playgroud)
然后在main.cpp我把:
#include <SFML/Audio.hpp>
#include <SFML/Graphics.hpp>
#include <map>
#include <string>
using namespace std;
#include "globals.h"
window(VideoMode( (800,600) , "Test") ); //line 22
Run Code Online (Sandbox Code Playgroud)
这怎么看似不正确.因为我得到这个错误:
main.cpp(22): error C2228: left of '.VideoMode' must have class/struct/union
这里有什么问题?
我正在使用sfml 2.0.我知道我可以在那里讨论论坛,但我不认为它与链接库有什么关系,因为我编译了一个示例项目很好,而且它几乎完全相同,我只是想尝试合并一个外部类.当我尝试编译时,我得到了这个
1> LINK:致命错误LNK1104:无法打开文件'C:\ Users\brr\documents\visual studio 2012\Projects\sfmlgame\Release\sfmlgame.exe'
我的代码如下:
main.cpp中:
#include "functions.h"
int main()
{
functions func;
std::cout << "Testing 123, testing 123!";
sf::CircleShape shape(100.f);
shape.setFillColor(sf::Color::Green);
bool running = true;
while (running)
{
func.window.clear();
func.window.draw(shape);
func.window.display();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
functions.h:
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include<SFML\Network.hpp>
#include <SFML/Window.hpp>
#include <iostream>
class functions
{
public:
functions(void);
~functions(void);
void Events();
void Window();
sf::RenderWindow window;
sf::Event event;
};
Run Code Online (Sandbox Code Playgroud)
functions.cpp:
#include "functions.h"
functions::functions(void)
{
}
functions::~functions(void)
{
}
void functions::Window(){
window.setSize(sf::Vector2u(800,600));
window.setTitle("Test");
} …Run Code Online (Sandbox Code Playgroud) 我之前使用过OpenGL,已经有一段时间了,但我认为这不是很糟糕.我在这段代码中遗漏了一些东西.我只是想看一个我正在使用该cube()功能绘制的立方体.
我做过/尝试过的事情......
我错过了什么?我所能看到的只是我指定的清晰颜色,填满了屏幕并嘲弄我.
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
void cube();
int gltest()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!", sf::Style::Default);
window.setVerticalSyncEnabled(true);
window.setActive(true);
window.resetGLStates();
sf::Vector2u wsize = window.getSize();
glClearColor(0.3f, 0.3f, 0.3f, 1.f);
glDepthMask(true);
glEnable(GL_DEPTH_TEST);
//to make sure I'm not missing anything here.
glDisable(GL_CULL_FACE);
glMatrixMode(GL_PROJECTION);
glViewport(0, 0, wsize.x, wsize.y);
gluPerspective(60, (float)wsize.x / (float)wsize.y, 0.1f, 512.f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
bool running = true;
while(running)
{
sf::Event event;
while(window.pollEvent(event))
{
switch(event.type)
{ …Run Code Online (Sandbox Code Playgroud) 我是sfml和c ++的新手.我有一个使用sfml库绘制图形的项目,但是当我向程序添加一个额外的线程时,它无法执行线程内的代码.这是我的代码:(请帮帮我!)
#include <SFML\Graphics.hpp>
#include <SFML\window.hpp>
#include <SFML\system.hpp>
#include <iostream>
#include <thread>
#include <chrono>
using namespace std;
int h(sf::RenderWindow* win){
//do something
win->close();
this_thread::sleep_for(chrono::milliseconds(10));
return 0;
}
int main(){
sf::RenderWindow window(sf::VideoMode(800,600),"My window");
thread t1(h,&window);
_sleep(10000000);
t1.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我收到错误,完全不知道为什么!
//create a circle shape.
sf::CircleShape shape;
shape.setRadius(25);
shape.setFillColor(sf::Color(100,250,250));
//circle collision geometry
circle circleTest(shape.getPosition.x,shape.getPosition.y,shape.getRadius())
Run Code Online (Sandbox Code Playgroud)
Circle是圆形碰撞几何体的类.它在构造函数上失败
(shape.getPosition.x,shape.getPosition.y,shape.getRadius())
我不知道为什么我得到错误,它工作正常然后突然给了我标题中的错误.
我做了一个圆圈作为我们的玩家并设定了重力,但它的工作速度更快,我甚至看不到.我认为它必须用sf :: time或sf :: clock做一些事情但是怎么做?我实际上没有得到这两个,所以任何代码示例和解释将不胜感激.这是我的代码: -
#include <SFML/Graphics.hpp>
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
sf::CircleShape shape(20);
shape.setFillColor(sf::Color::White);
shape.setPosition(380, 550);
shape.setOutlineColor(sf::Color::Green);
shape.setOutlineThickness(3);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
shape.move(0, -100);
}
if(event.KeyReleased)
{
if(event.key.code == sf::Keyboard::Up)
{
int x[] = { 10, 10, 10, 10, 10};
for (int y = 0; y <= 4; y++)
{
shape.move(0, x[y]);
}
}
}
}
window.clear(sf::Color::Black);
window.draw(shape);
window.display();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在c ++的SFML 2.1中,是否有一个sf :: Keyboard函数检查字母表中是否有任何字母被按下?
我知道如何检查某个键是否被按下,如下所示:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Key))
我是否必须键入所有这些:
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)&&sf::Keyboard::isKeyPressed(sf::Keyboard::B)&&sf::Keyboard::isKeyPressed(sf::Keyboard::C))
Run Code Online (Sandbox Code Playgroud)
...一路走来sf::Keyboard::Z,
还是有更简单的方法?
我是初学者所以请光临我.我正在尝试使用SFML 2.1,C++和MS Visual Studio Professional 2013将图像输出到屏幕上.我在尝试将文件加载到纹理时遇到意外错误.它输出一大堆随机字符.我确定它是如何配置Visual Studio的SFML库或代码的问题.有人能解决这个问题吗?谢谢.
以下是我运行程序时的截图(http://i.stack.imgur.com/uMdLT.png):

这是我的代码:
#include <SFML/Graphics.hpp>
#include <iostream>
#include <string>
using namespace std;
int main() {
sf::RenderWindow window;
window.create(sf::VideoMode(800, 600), "My First SFML Game!"); // initializing
sf::Texture jetTexture;
sf::Sprite jetImage;
// Getting Error here!
if (!jetTexture.loadFromFile("fighter jet.png"))
throw std::runtime_error("Could not load fighter jet.png");
jetImage.setTexture(jetTexture);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.draw(jetImage);
window.display();
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
对于所有配置属性,它们如下所示:
链接器 - >常规(http://i.stack.imgur.com/NZg7P.png):

链接器 - >输入( …
rippleShader.frag文件代码:
// attibutes from vertShader.vert
varying vec4 vColor;
varying vec2 vTexCoord;
// uniforms
uniform sampler2D uTexture;
uniform float uTime;
void main() {
float coef = sin(gl_FragCoord.y * 0.1 + 1 * uTime);
vTexCoord.y += coef * 0.03;
gl_FragColor = vColor * texture2D(uTexture, vTexCoord);
}
Run Code Online (Sandbox Code Playgroud)
vertShader.vert文件的代码:
#version 110
//varying "out" variables to be used in the fragment shader
varying vec4 vColor;
varying vec2 vTexCoord;
void main() {
vColor = gl_Color;
vTexCoord = (gl_TextureMatrix[0] * gl_MultiTexCoord0).xy;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
} …Run Code Online (Sandbox Code Playgroud) 我是SFML的新手,并按照SFML 2.5的SFML和Xcode教程尝试尝试构建和运行基本程序。
将Frameworks的/Library/Frameworks内容和extlibs的内容复制到/Library/Frameworks以及Xcode模板之后,我能够使用SFML App模板通过Xcode创建示例应用程序。
当我尝试构建它时,它失败并显示以下错误:

知道我做错了什么吗?
非常感谢帮助!