我爲opengl製作了一個加載器,它將頂點,頂點法線和所有這些東西都按順序讀入頂點。加載程序是正確的,我已經檢查了所有的值,它應該是什麼。出於某種原因,我仍然無法在屏幕上找到任何東西。OpenGL Draw Trouble
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include "Loader.h"
#define SC_WIDTH 600
#define SC_HEIGHT 600
#define REFRESH_RATE 0.03f
loader load;
int main()
{
// Create the main window
sf::Window App(sf::VideoMode(SC_WIDTH, SC_HEIGHT, 32), "SFML OpenGL");
// Create a clock for measuring time elapsed
sf::Clock clock;
//load file
load.openFile();
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
//lighing
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3,GL_FLOAT,0,&load.totalVertices);
glNormalPointer(GL_FLOAT,0,&load.faceNormal);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start game loop
while (App.isOpen())
{
// Process events
sf::Event Event;
while (App.pollEvent(Event))
{
// Close window : exit
if (Event.type == sf::Event::Closed)
App.close();
// Escape key : exit
if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
App.close();
// Resize event : adjust viewport
if (Event.type == sf::Event::Resized)
glViewport(0, 0, Event.size.width, Event.size.height);
}
// Set the active window before using OpenGL commands
// It's useless here because active window is always the same,
// but don't forget it if you use multiple windows or controls
App.setActive();
if((float)clock.getElapsedTime().asSeconds()>REFRESH_RATE){
// Clear colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPopMatrix();
glTranslatef(0.f,0.f,-10.f);
glDrawArrays(GL_TRIANGLES, 0,(GLsizei)(load.totalVertices.size()/3));
glPushMatrix();
clock.restart();
}
// Finally, display rendered frame on screen
App.display();
}
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
return EXIT_SUCCESS;
}
你有沒有忘記打電話'glOrtho'? –
glOrtho在網上看起來是什麼,但似乎沒有解釋。 – Student123
http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml幾乎建立了你的座標系。 –