Re: R: [Plib-users] Grrr.... I only get a black screen
Brought to you by:
sjbaker
From: Peter P. <pet...@st...> - 2004-08-26 12:26:26
|
Paolo Leoncini wrote: > Peter, > > try these: > > 1. disable lighting (state->disable(GL_LIGHTING)); > 2. add the fourth vertex color (just three colors set for four > vertices), or just add a single color, single normal (flat shading); > 3. move the sgSetCoord/setCamera to the draw() section and use rotate_ > as azimuth (4th param in sgSetCoord) in order to look around. > > Alternatively try loading a 3D model (get whatever 3DS model in > internet) instead of creating the leaf internally. > > Let's hope and see... > > Paolo > > > >>-----Messaggio originale----- >>Da: pli...@li... >>[mailto:pli...@li...] Per conto di >>Peter Poulsen >>Inviato: giovedì 26 agosto 2004 10.09 >>A: pli...@li... >>Oggetto: [Plib-users] Grrr.... I only get a black screen >> >> >>I have been playing around with wxWindow and ssg and I simply >>cannot get it >>working properly. >> >>My program can be found here: >>http://rafb.net/paste/results/TcxCwP78.html >>It shows to >>windows. One is drawn using ssg and _should_ show a white >>rectangle, but only shows a black screen. The other window is >>drawn using >>direct opengl calls, and shows (and should show) a spinning >>red rectangle. >> >>It can be compiled with this command: >>g++ wxssg.cc -o wxssg `wx-config --cxxflags --libs --gl-libs` >>-lplibssg >>-lplibul -lplibsg >> >>Can anybody explain to me why only the red rectangle works? >> >>PS. considering that it works with direct opengl calls, I >>don't think the >>problem is in wxWindow. >> Thanks alot! I finally got it working. I'm posting it here just for the archive. #include <iostream> #include <string> #include <cassert> #include <cmath> #include <wx/wx.h> #include <wx/glcanvas.h> #include <wx/notebook.h> #include <plib/ssg.h> bool ssg_init = false; class GL_Window : public wxGLCanvas { public: GL_Window(float c, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style=0, const wxString& name="GLCanvas", int* attribList = 0, const wxPalette& palette = wxNullPalette) : wxGLCanvas(parent, id, pos, size, style, name, attribList, palette), c_(c), rotate_(c) { } virtual ~GL_Window() {} void init(int color) { SetCurrent(); if(!ssg_init) { ssgInit(); ssg_init = true; } ssgGetCurrentContext()->setNearFar(0.1, 10000.0); ssgGetCurrentContext()->setCullface(false); sgVec3 sunposn ; sgSetVec3(sunposn, 0.0f, -10.0f, 0.0f) ; ssgGetLight(0)->setPosition(sunposn) ; root_ = new ssgRoot; ssgVertexArray* vertices = new ssgVertexArray; sgVec3 x = { -0.5, 0.0f, -0.5 }; sgVec3 y = { -0.5, 0.0f, 0.5 }; sgVec3 z = { 0.5, 0.0f, 0.5 }; sgVec3 w = { 0.5, 0.0f, -0.5 }; vertices->add(z); vertices->add(y); vertices->add(x); vertices->add(w); sgVec4 white = { 1.0f, color, color, 1.0f}; ssgColourArray* colours = new ssgColourArray; colours->add(white); ssgNormalArray* normals = new ssgNormalArray; sgVec3 normal = { 0, -1.0f, 0 }; normals->add(normal); ssgVtxTable* n = new ssgVtxTable(GL_QUADS, vertices, normals, NULL, colours); ssgSimpleState* state = new ssgSimpleState () ; state->disable(GL_TEXTURE_2D); state->disable(GL_COLOR_MATERIAL); state->disable(GL_LIGHTING); n->setState(state); n->setCullFace(false); root_->addKid(n); } void draw() { rotate_ += 0.01; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); SetCurrent(); glViewport(0, 0, (GLint)200, (GLint)200); if(root_) { sgCoord coord; sgSetCoord(&coord, 0.0f, -2.0f, 0.0f, 5*cos(rotate_), 0.0f, 0.0f); ssgGetCurrentContext()->setCamera(&coord); ssgCullAndDraw(root_); } SwapBuffers(); } void OnIdle(wxIdleEvent& event) { draw(); event.RequestMore(); } private: float c_; float rotate_; ssgRoot* root_; DECLARE_EVENT_TABLE(); }; class MyApp: public wxApp { virtual bool OnInit(); }; IMPLEMENT_APP(MyApp) bool MyApp::OnInit() { wxFrame* frame = new wxFrame((wxFrame *)NULL, -1, "Hello GL World", wxPoint(50,50), wxSize(450,340) ); frame->Show(TRUE); wxNotebook* book = new wxNotebook(frame, -1, wxPoint(-1,-1), wxSize(450,340)); GL_Window* MyGLCanvas = new GL_Window(1, book, -1, wxPoint(-1,-1), wxSize(200,200), wxSUNKEN_BORDER, "some text"); book->AddPage(MyGLCanvas, "One"); MyGLCanvas->init(1); MyGLCanvas = new GL_Window(0, book, -1, wxPoint(-1,-1), wxSize(200,200), wxSUNKEN_BORDER, "some text"); book->AddPage(MyGLCanvas, "Two"); MyGLCanvas->init(0); return TRUE; } BEGIN_EVENT_TABLE(GL_Window, wxGLCanvas) EVT_IDLE(GL_Window::OnIdle) END_EVENT_TABLE() -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing? A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail? |