- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的下一个问题(或问题)是,当我用 glm 加载模型时,我能够看穿模型的某些部分,例如:如果有两座山在另一座前面,我可以看穿越近的山。
我会展示一张图片,但由于纹理不起作用,所以无法理解。
问题在这里:
OLDER STUFF:vvvvvvvvvvvvvvvvvvvvvvv
我想知道的是:使用 glm 的最佳矩阵模式是什么?
我已经习惯了 GL_PROJECTION 但它在加载我的模型时给我带来了太多问题
并且使用 GL_MODELVIEW 我无法将相机向后移动
我也想知道:如果我使用 GL_MODELVIEW,那么如何移动场景中的“相机”?有没有办法设置一个,因为我最终必须这样做?
编辑:好吧,这里有一些代码可以给你们一些愿景:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
#include <assert.h>
#include <vector>
#include <glm/glm.h>
#include <glm/glmint.h>
#include "Item.hpp"
#include "Player.hpp"
///GOLD WAVE
using namespace std;
///GLOBAL VARIABLES
vector<sf::Sprite> SpriteList;
vector<GLMmodel*> ModelList;
vector<GLuint> _texture;
vector<Item*> DefItemList;
Player *pPlayer=new Player();
sf::RenderWindow GameWind(sf::VideoMode(800,600,32),"Carperon Game Window",sf::Style::Titlebar);
sf::View GameView(sf::FloatRect(0,0,25,18.75));//65x45 and 8x 0,0,65,45
///PROTOTYPE FUNCTIONS
void SFMLcreate();
void SFMLdraw();
void GLMcreate();
void GLdraw();
GLuint LoadTexture();
void GLiniti();
void ITEMdefault();
///////////////////////////////////STOP PROTOTYPES//////////////////////////////
//////////////////////////////////FUNCTIONS//////////////////////////////////
int main()
{
GLiniti();
SFMLcreate();
GLMcreate();
ITEMdefault();
sf::Event EventMain;
vector<sf::Sprite> ShowingBag;
sf::Image isbItem[45],iseItem[6];
sf::Sprite sbItem[45],seItem[6];
int BagSlotX[45] {0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30,0,15,30};
int BagSlotY[45] {0,0,0,15,15,15,30,30,30,0,0,0,15,15,15,30,30,30,0,0,0,15,15,15,30,30,30,0,0,0,15,15,15,30,30,30,0,0,0,15,15,15,30,30,30};
int EquipSlotY[6] {0,15,30,0,15,30};
bool BagUpdate = true;
int click = 0;
///MAIN PLAYER
pPlayer->PlayerCreate("Molma");
pPlayer->EquipFill(DefItemList[0]);
pPlayer->AddItem(DefItemList[1]);
pPlayer->AddItem(DefItemList[2]);
pPlayer->AddItem(DefItemList[3]);
pPlayer->AddItem(DefItemList[4]);
while(GameWind.IsOpened())
{
while(GameWind.GetEvent(EventMain))
{
//If its closed
if(EventMain.Type==sf::Event::Closed)
{
//Close the whole thing!
//GameWind.Close();
GameWind.Close();
}
}
float MouseX = (GameWind.GetInput().GetMouseX()/32.f);
float MouseY = (GameWind.GetInput().GetMouseY()/32.f);
if(GameWind.GetInput().IsKeyDown(sf::Key::Escape))
{
GameWind.Close();
//GameWind.Close();
}
/////////////////////////////BEGIN INPUT/////////////////////////////////////////////////
if(GameWind.GetInput().IsKeyDown(sf::Key::Return))
{
pPlayer->RandHealth();
BagUpdate = true;
}
if(GameWind.GetInput().IsKeyDown(sf::Key::Z))
{
pPlayer->GetHit();
}
if(GameWind.GetInput().IsMouseButtonDown(sf::Mouse::Right)&&click<=0)
{
for(int a=0;a<pPlayer->Bag.size();++a)
{
if(MouseX>((17.f+(BagSlotX[a]))/16.f)&&MouseX<(((32.f+(BagSlotX[a]))/16.f))&&MouseY>((60.f+(BagSlotY[a]))/16.f)&&MouseY<(((75.f+(BagSlotY[a]))/16.f)))
{
pPlayer->ItemUse(pPlayer->Bag[a],a);
BagUpdate = true;
click=20;
//cout << "Item used!" << endl;
}
}
for(int b=0;b<6;++b)
{
if(MouseX>2.f/16.f&&MouseX<17.f/16.f&&MouseY>((60.f+(EquipSlotY[b]))/16.f)&&MouseY<((75.f+(EquipSlotY[b]))/16.f)&&pPlayer->EqSpot[b]->get_Type()!="Blank Spot")
{
pPlayer->Unequip(pPlayer->EqSpot[b],DefItemList[0],b);
BagUpdate = true;
click=20;
}
}
}
///////////////////////////////END INPUT/////////////////////////////////////////////////
//////////////////////////////AUTO FUNCTIONS//////////////////////////////////////////////
pPlayer->Guarding();
pPlayer->HitTiming();
if(BagUpdate)
{
for(int a=0;a<pPlayer->Bag.size();++a)
{
isbItem[a].LoadFromFile("Graphics/Items.png");
sbItem[a].SetImage(isbItem[a]);
sbItem[a].SetPosition(((17.f+(BagSlotX[a]))/16.f),((60.f+(BagSlotY[a]))/16.f));
}
for(int b=0;b<6;++b)
{
iseItem[b].LoadFromFile("Graphics/Items.png");
seItem[b].SetImage(iseItem[b]);
seItem[b].SetPosition(2.f/16.f,((60.f+(EquipSlotY[b]))/16.f));
}
BagUpdate=false;
}
if(click>0)
{
click-=1;
}
SpriteList[22].SetPosition(MouseX,MouseY);
GameWind.SetView(GameView);
GLdraw();
SFMLdraw();
for(int a=((pPlayer->get_BagShow())*9);a<((pPlayer->get_BagShow()*9)+9);++a)//18-27=A
{
if(a<pPlayer->Bag.size())
{
sbItem[a].Resize(15.f/16.f,15.f/16.f);
sbItem[a].SetSubRect(sf::IntRect((pPlayer->Bag[a]->get_Index()*15),0,((pPlayer->Bag[a]->get_Index()*15)+15),15));
GameWind.Draw(sbItem[a]);
//cout << "Items Drawn! Position: " << BagSlotX[a] << "," << BagSlotY[a] << "Item: " << a << endl;
//image pos resize subrect
}
}
for(int b=((pPlayer->get_EquipShow())*3);b<((pPlayer->get_EquipShow()*3)+3);++b)
{
seItem[b].Resize(15.f/16.f,15.f/16.f);
seItem[b].SetSubRect(sf::IntRect((pPlayer->EqSpot[b]->get_Index()*15),0,((pPlayer->EqSpot[b]->get_Index()*15)+15),15));
GameWind.Draw(seItem[b]);
}
GameWind.Draw(SpriteList[16]);
GameWind.Draw(SpriteList[20]);
GameWind.Draw(SpriteList[21]);
GameWind.Draw(SpriteList[22]);
GameWind.Display();
GameWind.SetFramerateLimit(60);
}
return EXIT_SUCCESS;
}
void SFMLcreate()
{
sf::Image iStatBack,iStatWindow,ipHealth,ipEnergy,ipStr,ipDex,ipInt,ipEnd,ipCrit,ipSwd,ipAxe,ipBow,ipStar,ipWand,ipStaff,ipBag,ipEquip,ipSkills,ipNumHP,ipNumEP,ipGuard,ipRank,ipRankXP,iCursor;
sf::Sprite StatBack,StatWindow,pHealth,pEnergy,pStr,pDex,pInt,pEnd,pCrit,pSwd,pAxe,pBow,pStar,pWand,pStaff,pBag,pEquip,pSkills,pNumHP,pNumEP,pGuard,pRank,pRankXP,Cursor;
sf::Font MainFont;
//LoadFromFile
iStatBack.LoadFromFile("Graphics/Player Stats/Stats Back.png");
iStatWindow.LoadFromFile("Graphics/Player Stats/StatWindow2.png");
ipHealth.LoadFromFile("Graphics/Player Stats/Health.png");
ipEnergy.LoadFromFile("Graphics/Player Stats/Energy.png");
ipStr.LoadFromFile("Graphics/Player Stats/Strength.png");
ipDex.LoadFromFile("Graphics/Player Stats/Dexterity.png");
ipInt.LoadFromFile("Graphics/Player Stats/Intellegence.png");
ipEnd.LoadFromFile("Graphics/Player Stats/Endurance.png");
ipCrit.LoadFromFile("Graphics/Player Stats/Critical.png");
ipSwd.LoadFromFile("Graphics/Player Stats/Sword Mast.png");
ipAxe.LoadFromFile("Graphics/Player Stats/Axe Mast.png");
ipBow.LoadFromFile("Graphics/Player Stats/Bow Mast.png");
ipStar.LoadFromFile("Graphics/Player Stats/Star Mast.png");
ipWand.LoadFromFile("Graphics/Player Stats/Wand Mast.png");
ipStaff.LoadFromFile("Graphics/Player Stats/Staff Mast.png");
ipBag.LoadFromFile("Graphics/Player Stats/Bag.png");
ipEquip.LoadFromFile("Graphics/Player Stats/Bag.png");
ipSkills.LoadFromFile("Graphics/Player Stats/Skill.png");
ipNumHP.LoadFromFile("Graphics/Player Stats/Number HE.png");
ipNumEP.LoadFromFile("Graphics/Player Stats/Number HE.png");
ipGuard.LoadFromFile("Graphics/Player Stats/Guard.png");
ipRank.LoadFromFile("Graphics/Player Stats/Rank.png");
ipRankXP.LoadFromFile("Graphics/Player Stats/RankXP.png");
iCursor.LoadFromFile("Graphics/Cursor.png");
//SetSmooth()
ipStr.SetSmooth(false);
ipDex.SetSmooth(false);
ipInt.SetSmooth(false);
ipEnd.SetSmooth(false);
ipCrit.SetSmooth(false);
ipSwd.SetSmooth(false);
ipAxe.SetSmooth(false);
ipBow.SetSmooth(false);
ipStar.SetSmooth(false);
ipWand.SetSmooth(false);
ipStaff.SetSmooth(false);
ipSkills.SetSmooth(false);
ipHealth.SetSmooth(false);
ipEnergy.SetSmooth(false);
ipGuard.SetSmooth(false);
ipNumHP.SetSmooth(false);
ipNumEP.SetSmooth(false);
ipRankXP.SetSmooth(false);
ipRank.SetSmooth(false);
//SetImage!!
StatBack.SetImage(iStatBack);
StatWindow.SetImage(iStatWindow);
pHealth.SetImage(ipHealth);
pEnergy.SetImage(ipEnergy);
pStr.SetImage(ipStr);
pDex.SetImage(ipDex);
pInt.SetImage(ipInt);
pEnd.SetImage(ipEnd);
pCrit.SetImage(ipCrit);
pSwd.SetImage(ipSwd);
pAxe.SetImage(ipAxe);
pBow.SetImage(ipBow);
pStar.SetImage(ipStar);
pWand.SetImage(ipWand);
pStaff.SetImage(ipStaff);
pBag.SetImage(ipBag);
pEquip.SetImage(ipEquip);
pSkills.SetImage(ipSkills);
pNumHP.SetImage(ipNumHP);
pNumEP.SetImage(ipNumEP);
pGuard.SetImage(ipGuard);
pRank.SetImage(ipRank);
pRankXP.SetImage(ipRankXP);
Cursor.SetImage(iCursor);
//SetPosition(x,y)!!
StatBack.SetPosition(0,0);
StatWindow.SetPosition(-5.f/16.f,-5.f/16.f);
pHealth.SetPosition(5.f/16.f,23.25f/16.f);
pEnergy.SetPosition(5.f/16.f,31.5f/16.f);
pStr.SetPosition(59.f/16.f,23.f/16.f);
pDex.SetPosition(59.f/16.f,35.f/16.f);
pInt.SetPosition(59.f/16.f,47.f/16.f);
pEnd.SetPosition(3.f/16.f,37.f/16.f);
pCrit.SetPosition(32.f/16.f,37.f/16.f);
pSwd.SetPosition(63.f/16.f,21.f/16.f);
pAxe.SetPosition(63.f/16.f,29.f/16.f);
pBow.SetPosition(63.f/16.f,33.f/16.f);
pStar.SetPosition(63.f/16.f,41.f/16.f);
pWand.SetPosition(63.f/16.f,45.f/16.f);
pStaff.SetPosition(63.f/16.f,53.f/16.f);
pBag.SetPosition(2.f/16.f,60.f/16.f);
pEquip.SetPosition(2.f/16.f,60.f/16.f);
pSkills.SetPosition(71.f/16.f,61.f/16.f);
pNumHP.SetPosition(4.f/16.f,22.f/16.f);
pNumEP.SetPosition(4.f/16.f,30.f/16.f);
pGuard.SetPosition(4.f/16.f,22.5f/16.f);
pRank.SetPosition(41.5f/16.f,25.f/16.f);
pRankXP.SetPosition(39.5f/16.f,23.f/16.f);
//VECTOR STORE
SpriteList.push_back(StatWindow);
SpriteList.push_back(pHealth);
SpriteList.push_back(pEnergy);
SpriteList.push_back(pStr);
SpriteList.push_back(pDex);
SpriteList.push_back(pInt);
SpriteList.push_back(pEnd);
SpriteList.push_back(pCrit);
SpriteList.push_back(pSwd);
SpriteList.push_back(pAxe);
SpriteList.push_back(pBow);
SpriteList.push_back(pStar);
SpriteList.push_back(pWand);
SpriteList.push_back(pStaff);
SpriteList.push_back(pBag);
SpriteList.push_back(pEquip);
SpriteList.push_back(pSkills);
SpriteList.push_back(pNumHP);
SpriteList.push_back(pNumEP);
SpriteList.push_back(pGuard);
SpriteList.push_back(pRank);
SpriteList.push_back(pRankXP);
SpriteList.push_back(Cursor);
}
void SFMLdraw()
{
//////////////////////////////STAT RESIZE/SUBRECT///////////////////////////////////////
SpriteList[1].SetSubRect(sf::IntRect(0,0,120,12)); //30,3
SpriteList[2].SetSubRect(sf::IntRect(0,0,120,12)); //30,3
SpriteList[3].SetSubRect(sf::IntRect(pPlayer->get_Str()*28,0,(pPlayer->get_Str()*28)+28,7)); //28,7
SpriteList[4].SetSubRect(sf::IntRect(pPlayer->get_Dex()*28,0,(pPlayer->get_Dex()*28)+28,7)); //28,7
SpriteList[5].SetSubRect(sf::IntRect(pPlayer->get_Int()*28,0,(pPlayer->get_Int()*28)+28,7)); //28,7
SpriteList[6].SetSubRect(sf::IntRect(pPlayer->get_End()*28,0,(pPlayer->get_End()*28)+28,7)); //28,7
SpriteList[7].SetSubRect(sf::IntRect(pPlayer->get_Crit()*28,0,(pPlayer->get_Crit()*28)+28,7)); //28,7
SpriteList[8].SetSubRect(sf::IntRect(pPlayer->get_Sword()*18,0,(pPlayer->get_Sword()*18)+18,3)); //18,3
SpriteList[9].SetSubRect(sf::IntRect(pPlayer->get_Axe()*18,0,(pPlayer->get_Axe()*18)+18,3)); //18,3
SpriteList[10].SetSubRect(sf::IntRect(pPlayer->get_Bow()*18,0,(pPlayer->get_Bow()*18)+18,3)); //18,3
SpriteList[11].SetSubRect(sf::IntRect(pPlayer->get_Star()*18,0,(pPlayer->get_Star()*18)+18,3)); //18,3
SpriteList[12].SetSubRect(sf::IntRect(pPlayer->get_Wand()*18,0,(pPlayer->get_Wand()*18)+18,3)); //18,3
SpriteList[13].SetSubRect(sf::IntRect(pPlayer->get_Staff()*18,0,(pPlayer->get_Staff()*18)+18,3)); //18,3
SpriteList[14].SetSubRect(sf::IntRect((pPlayer->get_BagShow()*60)+120,0,(pPlayer->get_BagShow()*60)+180,48));
SpriteList[15].SetSubRect(sf::IntRect(pPlayer->get_EquipShow()*60,0,(pPlayer->get_EquipShow()*60)+60,48));
SpriteList[16].SetSubRect(sf::IntRect(pPlayer->get_SkillShow()*30,0,(pPlayer->get_SkillShow()*30)+30,64));
SpriteList[17].SetSubRect(sf::IntRect(pPlayer->get_Health()*7,0,(pPlayer->get_Health()*7)+7,5));
SpriteList[18].SetSubRect(sf::IntRect(pPlayer->get_Energy()*7,0,(pPlayer->get_Energy()*7)+7,5));
SpriteList[19].SetSubRect(sf::IntRect(0,0,128,20));
SpriteList[20].SetSubRect(sf::IntRect(pPlayer->get_Rank()*14,0,(pPlayer->get_Rank()*14)+14,6));//10
SpriteList[21].SetSubRect(sf::IntRect(pPlayer->get_tRankXPN()*18,0,(pPlayer->get_tRankXPN()*18)+18,10));//16
/////////////////////RESIZE PART
SpriteList[0].Resize(410.f/16.f,310.f/16.f);
SpriteList[1].Resize(pPlayer->get_tHealth()/64.f,12.f/64.f);
SpriteList[2].Resize(pPlayer->get_tEnergy()/64.f,12.f/64.f);
SpriteList[3].Resize(28.f/16.f,7.f/16.f);
SpriteList[4].Resize(28.f/16.f,7.f/16.f);
SpriteList[5].Resize(28.f/16.f,7.f/16.f);
SpriteList[6].Resize(28.f/16.f,7.f/16.f);
SpriteList[7].Resize(28.f/16.f,7.f/16.f);
SpriteList[8].Resize(18.f/16.f,3.f/16.f);
SpriteList[9].Resize(18.f/16.f,3.f/16.f);
SpriteList[10].Resize(18.f/16.f,3.f/16.f);
SpriteList[11].Resize(18.f/16.f,3.f/16.f);
SpriteList[12].Resize(18.f/16.f,3.f/16.f);
SpriteList[13].Resize(18.f/16.f,3.f/16.f);
SpriteList[14].Resize(60.f/16.f,48.f/16.f);
SpriteList[15].Resize(60.f/16.f,48.f/16.f);
SpriteList[16].Resize(30.f/16.f,64.f/16.f);
SpriteList[17].Resize(7.f/16.f,5.f/16.f);
SpriteList[18].Resize(7.f/16.f,5.f/16.f);
SpriteList[19].Resize(pPlayer->get_tGuard()/64.f,20.f/64.f);
SpriteList[20].Resize(14.f/16.f,6.f/16.f);
SpriteList[21].Resize(18.f/16.f,10.f/16.f);
SpriteList[22].Resize(15.f/16.f,15.f/16.f);
///////////////////////////////////END RESIZE/SUBRECT!!!////////////////////////////////
////////////////////////////////////DONT TOUCH/////////////////////////////////////////
///////////////////////////////NOW YOU CAN TOUCH//////////////////////////////////////////
//////////////////////////////DRAW STARTS///////////////////////////////////////////////
GameWind.Draw(SpriteList[0]);
GameWind.Draw(SpriteList[19]);
GameWind.Draw(SpriteList[1]);
GameWind.Draw(SpriteList[17]);
GameWind.Draw(SpriteList[2]);
GameWind.Draw(SpriteList[18]);
GameWind.Draw(SpriteList[3]);
GameWind.Draw(SpriteList[4]);
GameWind.Draw(SpriteList[5]);
GameWind.Draw(SpriteList[6]);
GameWind.Draw(SpriteList[7]);
GameWind.Draw(SpriteList[8]);
GameWind.Draw(SpriteList[9]);
GameWind.Draw(SpriteList[10]);
GameWind.Draw(SpriteList[11]);
GameWind.Draw(SpriteList[12]);
GameWind.Draw(SpriteList[13]);
GameWind.Draw(SpriteList[14]);
GameWind.Draw(SpriteList[15]);
}
void GLMcreate()
{
GLMmodel* World = glmReadOBJ("3Dobject/WorldMap3Dv1.obj");
glmUnitize(World);
glmScale(World,1);
}
void GLdraw()
{
GameWind.SetActive();
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
////////AMBIENT LIGHT
GLfloat AmbientColor[] = {0.05f,0.05f,0.2f,1.0f};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,AmbientColor);
////////POSITIONED LIGHT
GLfloat LightColor0[] = {0.5f,0.5f,0.5f,1.0f};
GLfloat LightPos0[] = {4.0f,4.0f,0.0f,1.0f};
glLightfv(GL_LIGHT0,GL_DIFFUSE,LightColor0);
glLightfv(GL_LIGHT0,GL_POSITION,LightPos0);
////////DIRECTED LIGHT
GLfloat LightColor1[] = {0.9f,0.9f,0.6f,1.0f};
/////Coming from direction (x,y,z)
GLfloat LightPos1[] = {-1.0f,0.5f,0.5f,0.0f};
glLightfv(GL_LIGHT1,GL_DIFFUSE,LightColor1);
glLightfv(GL_LIGHT1,GL_POSITION,LightPos1);
///DRAWING MODELS
}
void GLiniti()
{
GameWind.PreserveOpenGLStates(true);
GameWind.ShowMouseCursor(false);
glClearDepth(1.f);
glClearColor(0.2f,0.2f,0.8f,1.f);
/////z buffer
glEnable(GL_POLYGON_STIPPLE);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHT1);
glEnable(GL_NORMALIZE);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glCullFace(GL_FRONT);
glFrontFace(GL_CW);
glShadeModel(GL_SMOOTH);
glDepthMask(GL_TRUE);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glDepthFunc(GL_LEQUAL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(50.f,(double)800 / (double)600,200.f,0.f);
glTranslatef(0.f, 0.f, -10.0f);
}
GLuint LoadTexture(sf::Image image)
{
GLuint Texture;
glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA,image.GetWidth(),image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE,image.GetPixelsPtr());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
return Texture;
}
void ITEMdefault()
{
Blank *BlankSpot=new Blank();
BlankSpot->ItemCreate(0,0,0,0,0,0,0);
///TEST ITEMS
Weapon *sword=new Weapon();
sword->ItemCreate(0,0,0,sf::Randomizer::Random(0,5),1,0,sf::Randomizer::Random(1,4));
Armor *sword2=new Armor();
sword2->ItemCreate(0,0,0,sf::Randomizer::Random(0,5),2,0,sf::Randomizer::Random(1,4));
Necklace *sword3=new Necklace();
sword3->ItemCreate(0,0,0,sf::Randomizer::Random(0,5),3,0,sf::Randomizer::Random(1,4));
Consume *hppotion=new Consume();
hppotion->ItemCreate(0,0,0,6,83,0,6);
DefItemList.push_back(BlankSpot);
DefItemList.push_back(sword);
DefItemList.push_back(sword2);
DefItemList.push_back(sword3);
DefItemList.push_back(hppotion);
}
最佳答案
没有一种特定的矩阵模式也可以切换 OpenGL。我已经在这篇文章中解释过了 OpenGL: What is MatrixMode? ,我将在此处进行简单复制:
OpenGL 使用多个矩阵来转换几何图形和相关数据。这些矩阵是:
所有这些矩阵一直都在使用。由于它们遵循所有相同的规则,OpenGL 只有一组矩阵操作函数:glPushMatrix、glPopMatrix、glLoadIdentity、glLoadMatrix、glMultMatrix、glTranslate、glRotate、glScale、glOrtho、glFrustum。
glMatrixMode 选择这些操作作用于哪个矩阵。假设您想编写一些 C++ 命名空间包装器,它可能看起来像这样:
namespace OpenGL {
// A single template class for easy OpenGL matrix mode association
template<GLenum mat> class Matrix
{
public:
void LoadIdentity() const
{ glMatrixMode(mat); glLoadIdentity(); }
void Translate(GLfloat x, GLfloat y, GLfloat z) const
{ glMatrixMode(mat); glTranslatef(x,y,z); }
void Translate(GLdouble x, GLdouble y, GLdouble z) const
{ glMatrixMode(mat); glTranslated(x,y,z); }
void Rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z) const
{ glMatrixMode(mat); glRotatef(angle, x, y, z); }
void Rotate(GLdouble angle, GLdouble x, GLdouble y, GLdouble z) const
{ glMatrixMode(mat); glRotated(angle, x, y, z); }
// And all the other matrix manipulation functions
// using overloading to select proper OpenGL variant depending on
// function parameters, and all the other C++ whiz.
// ...
};
//
const Matrix<GL_MODELVIEW> Modelview;
const Matrix<GL_PROJECTION> Projection;
const Matrix<GL_TEXTURE> Texture;
const Matrix<GL_COLOR> Color;
}
稍后您可以在 C++ 程序中编写
void draw_something()
{
OpenGL::Projection::LoadIdentity();
OpenGL::Projection::Frustum(...);
OpenGL::Modelview::LoadIdentity();
OpenGL::Modelview::Translate(...);
// drawing commands
}
不幸的是,C++ 不能模板命名空间,或者在实例上应用using
(或with
)(其他语言有这个),否则我会写类似的东西(无效的 C++)
void draw_something_else()
{
using namespace OpenGL;
with(Projection) { // glMatrixMode(GL_PROJECTION);
LoadIdentity(); // glLoadIdentity();
Frustum(...); // glFrustum(...);
}
with(Modelview) { // glMatrixMode(GL_MODELVIEW);
LoadIdentity(); // glLoadIdentity();
Translate(...); // glTranslatef(...);
}
}
我认为最后一段(伪)代码清楚地表明了这一点:glMatrixMode 是一种 OpenGL 的 with
语句。
所有矩阵都在渲染过程中使用!
关于c++ - 使用 GLM 的最佳 glMatrixMode() 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5384614/
将 glRotatef() 放在 glMatrixMode(GL_PROJECTION); 之后有什么区别 glMatrixMode(GL_PROJECTION); glLoadIdentity();
glMatrixMode(GL_PROJECTION)有什么区别和 glMatrixMode(GL_MODELVIEW) ? #include #include #include #define
我学习过的大多数 Android OpenGL ES 教程都有这样的 onSurfaceChanged() 函数: public void onSurfaceChanged( GL10 gl, int
我收到 0 个错误,但我在控制台中得到了这个: >Exception in thread "main" java.lang.NullPointerException >>at org.lwjgl.
我开始研究 OpenGL 的一些东西,我看到了很多调用 glMatrixMode 函数的例子。 根据我收集到的信息,将其设置为 GL_MODELVIEW 或 GL_PROJECTION(等)将激活该特
所以我正在阅读this LWJGL wiki 上的文章提到,“当使用‘向前兼容’上下文时,任何标记为已弃用的功能都将被删除。” 现在,当我实现与显示的前向兼容性时,每当我调用 glMatrixMode
static void resize(int width, int height) { const float ar = (float) width / (float) height;
我目前正在使用 SDL 1.2.4 和 C++Builder 10.0 Seattle。我设置了一个简单的测试程序来检查是否一切正常。 以下代码编译时没有警告或错误,但给我一个运行时错误: Excep
我正在阅读一本关于 OpenGL、SDL 的书,并且已经阅读了一些 OpenGL 文档。我也读过这篇文章:What does glLoadIdentity() do in OpenGL? 我正在掌握
我的下一个问题(或问题)是,当我用 glm 加载模型时,我能够看穿模型的某些部分,例如:如果有两座山在另一座前面,我可以看穿越近的山。 我会展示一张图片,但由于纹理不起作用,所以无法理解。 问题在这里
我想将 OpenGL 与 C++ 结合使用来创建一个带有“相机”(透视图)和要查看的对象的基本场景。我找到了示例代码 here .但出于某种原因,尽管我已将所有必要的包含和库捆绑在一起(见下文), /
在查看红皮书中的 reshape 示例时,我通常会发现如下内容: void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLs
我有一个 iPhone 应用程序,我在 appDidFinishLaunching 中调用这三个函数: glMatrixMode(GL_PROJECTION); glOrthof(0, rect.si
在 Mac 上的 Parallels 中运行的 Windows 10 上,android 模拟器在启动时崩溃 C:\Android-SDK>.\tools\bin\avdmanager create
我的 OpenGL C++ 项目突然停止识别 glMatrixMode(GL_MODELVIEW)。我去吃晚饭,然后我的项目无法构建。 我在带有 CDT 插件的 Eclipse 中使用 Windows
我将先发布代码,然后发布以下问题: import java.util.Properties; import org.lwjgl.Sys; import org.lwjgl.input.Keyboard
使用 opengl es 演练黑莓 10 sdk。它使用 2 个命令,即: glMatrixMode(GL_PROJECTION); glLoadIdentity(); 及以后: glMatrixMo
我是一名优秀的程序员,十分优秀!