Example #1
0
/* OGLCanvas::onPaint
 * Called when the gfx canvas has to be redrawn
 *******************************************************************/
void OGLCanvas::onPaint(wxPaintEvent& e) {
	wxPaintDC(this);

	if (IsShown()) {
		// Set context to this window
#ifdef USE_SFML_RENDERWINDOW
#if SFML_VERSION_MAJOR < 2
		sf::RenderWindow::SetActive();
		Drawing::setRenderTarget(this);
		SetView(sf::View(sf::FloatRect(0.0f, 0.0f, GetSize().x, GetSize().y)));
#else
		sf::RenderWindow::setActive();
		Drawing::setRenderTarget(this);
		setView(sf::View(sf::FloatRect(0.0f, 0.0f, GetSize().x, GetSize().y)));
#endif//SFML_VERSION_MAJOR
#else
		setContext();
#endif//USE_SFML_RENDERWINDOW

		// Init if needed
		if (!init_done)
			init();

		// Draw content
		draw();
	}
}
Example #2
0
void BasicGLPane::render( wxPaintEvent& evt )
{
    if(!IsShown()) return;
    
    wxGLCanvas::SetCurrent(*m_context);
    wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event
	
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
    // ------------- draw some 2D ----------------
    prepare2DViewport(0,0,getWidth()/2, getHeight());
    glLoadIdentity();
	
    // white background
    glColor4f(1, 1, 1, 1);
    glBegin(GL_QUADS);
    glVertex3f(0,0,0);
    glVertex3f(getWidth(),0,0);
    glVertex3f(getWidth(),getHeight(),0);
    glVertex3f(0,getHeight(),0);
    glEnd();
	
    // red square
    glColor4f(1, 0, 0, 1);
    glBegin(GL_QUADS);
    glVertex3f(getWidth()/8, getHeight()/3, 0);
    glVertex3f(getWidth()*3/8, getHeight()/3, 0);
    glVertex3f(getWidth()*3/8, getHeight()*2/3, 0);
    glVertex3f(getWidth()/8, getHeight()*2/3, 0);
    glEnd();
    
    // ------------- draw some 3D ----------------
    prepare3DViewport(getWidth()/2,0,getWidth(), getHeight());
    glLoadIdentity();
	
    glColor4f(0,0,1,1);
    glTranslatef(0,0,-5);
    glRotatef(50.0f, 0.0f, 1.0f, 0.0f);
    
    glColor4f(1, 0, 0, 1);
    for (int i = 0; i < 6; i++)
    {
        glBegin(GL_LINE_STRIP);
        glVertex3fv(&v[faces[i][0]][0]);
        glVertex3fv(&v[faces[i][1]][0]);
        glVertex3fv(&v[faces[i][2]][0]);
        glVertex3fv(&v[faces[i][3]][0]);
        glVertex3fv(&v[faces[i][0]][0]);
        glEnd();
    }
    
    glFlush();
    SwapBuffers();
}
Example #3
0
void GLCanvas::draw()
{
    if ( useDebugTimers )
    {
        lastNonDrawTime = drawStopwatch.Time();
        lastNonDrawTimeMax += lastNonDrawTime;
        drawStopwatch.Start();
    }

    if( !IsShown() ) return;

    SetCurrent( *glContext );
    wxPaintDC( this );

    if ( grav != NULL )
        grav->draw();

#if defined(USE_SAGE)
    if (sageInitialized) {
      GLubyte* rgbBuffer = (GLubyte *)sageInf->getBuffer();
      glReadPixels(0, 0, winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, rgbBuffer);	
      sageInf->swapBuffer();
    }
#endif

    SwapBuffers();

    if ( useDebugTimers )
    {
        lastDrawTime = drawStopwatch.Time();
        lastDrawTimeMax += lastDrawTime;
        drawStopwatch.Start();

        counter = (counter+1) % counterMax;
        if ( counter == 0 )
        {
            lastDrawTimeAvg = lastDrawTimeMax / (float)counterMax;
            lastNonDrawTimeAvg = lastNonDrawTimeMax / (float)counterMax;
            lastDrawTimeMax = 0;
            lastNonDrawTimeMax = 0;
        }

        fpsCounter++;
        long elapsed = fpsStopwatch.Time();
        if ( elapsed > 500 )
        {
            fpsResult = (float)fpsCounter * 1000.0f / (float)elapsed;
            fpsCounter = 0;
            fpsStopwatch.Start();
        }
    }
}
Example #4
0
void MerryMainPanel::OnPaintEvent(wxPaintEvent& e)
{
	wxPaintDC dc = wxPaintDC(this);
	dc.Clear();
	if (m_background.IsOk())
	{
		dc.DrawBitmap(m_background, 0, 0, false);
	}
	if (title_align == -1)
		return;

	dc.SetTextForeground(skin->get(TITLE_TEXT_COLOR));
	dc.DrawLabel(title_info,title_cfg,title_align);
}
Example #5
0
//------------------------------------------------------------------------------
void VisualModelPanel::OnPaint(wxPaintEvent& event)
{
	if (interfaceEnabled && currentSpacecraft->modelFile == wxT(""))
	{
		interfaceEnabled = false;
		ToggleInterface(false);
	}
	if (!interfaceEnabled && currentSpacecraft->modelFile != wxT(""))
	{
		interfaceEnabled = true;
		ToggleInterface(true);
	}
   wxPaintDC(this);
}
Example #6
0
void BasicGLPane::render( wxPaintEvent& evt )
{
    if(!IsShown()) return;
    
    wxGLCanvas::SetCurrent(*m_context);
    wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    prepare2DViewport(0,0,getWidth(), getHeight());
    glLoadIdentity();
    
    if (!buf.empty()) paint_buffer();


    glFlush();
    SwapBuffers();
}
Example #7
0
void GLCanvas::draw()
{
    if ( useDebugTimers )
    {
        lastNonDrawTime = drawStopwatch.Time();
        lastNonDrawTimeMax += lastNonDrawTime;
        drawStopwatch.Start();
    }

    if( !IsShown() ) return;

    SetCurrent( *glContext );
    wxPaintDC( this );

    if ( objectMan != NULL )
        objectMan->draw();

    SwapBuffers();

    if ( useDebugTimers )
    {
        lastDrawTime = drawStopwatch.Time();
        lastDrawTimeMax += lastDrawTime;
        drawStopwatch.Start();

        counter = (counter+1) % counterMax;
        if ( counter == 0 )
        {
            lastDrawTimeAvg = lastDrawTimeMax / (float)counterMax;
            lastNonDrawTimeAvg = lastNonDrawTimeMax / (float)counterMax;
            lastDrawTimeMax = 0;
            lastNonDrawTimeMax = 0;
        }

        fpsCounter++;
        long elapsed = fpsStopwatch.Time();
        if ( elapsed > 500 )
        {
            fpsResult = (float)fpsCounter * 1000.0f / (float)elapsed;
            fpsCounter = 0;
            fpsStopwatch.Start();
        }
    }
}
Example #8
0
void Canvas::Paint(wxPaintEvent& event)
{
	wxPaintDC(this);
	SetCurrent();

	if(!flag)
	{
		InitGL();
		flag = true;
	}
	
	if(dimension)
	{
	scene.setViewSize(0,0,GetSize().x,GetSize().y);	
	scene.Draw();
	}

	SwapBuffers();
}
void GLImagePane::saveScreen(const char* filePath) {
	wxGLCanvas::SetCurrent(*m_context);
	wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event
	int w = GetParent()->GetSize().x;
	int h = GetSize().y;
	ImgRGB imgData(w, h);
	glReadPixels(-1, 0, w - 1, h, GL_BGR, GL_UNSIGNED_BYTE, imgData.data);
	cv::Mat img(h, w, CV_8UC3, imgData);
	cv::line(img, cv::Point2i(0, 0), cv::Point2i(0, h - 1), cv::Scalar(0, 0, 0),
			2, CV_AA, 0);
	cv::line(img, cv::Point2i(0, h - 1), cv::Point2i(w - 1, h - 1),
			cv::Scalar(0, 0, 0), 2, CV_AA, 0);
	cv::line(img, cv::Point2i(w - 1, h - 1), cv::Point2i(w - 1, 0),
			cv::Scalar(0, 0, 0), 2, CV_AA, 0);
	cv::line(img, cv::Point2i(w - 1, 0), cv::Point2i(0, 0), cv::Scalar(0, 0, 0),
			2, CV_AA, 0);
	CvMat cvImg = img;
	cvFlip(&cvImg, 0);
	cv::imwrite(filePath, img);
}
Example #10
0
void GLScenePane::saveScreen(const char* filePath) {
	wxGLCanvas::SetCurrent(*m_context);
	wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event
	int w = GetParent()->GetScreenRect().width;
	int h = GetSize().y;
	unsigned char* imgData = new unsigned char[w * h * 3];
	glReadPixels(-1, 0, w - 1, h, GL_BGR, GL_UNSIGNED_BYTE, imgData);
	cv::Mat img(h, w, CV_8UC3, imgData);
	cv::line(img, cv::Point2i(0, 0), cv::Point2i(0, h - 1), cv::Scalar(0, 0, 0),
			1, CV_AA, 0);
	cv::line(img, cv::Point2i(0, h - 1), cv::Point2i(w - 1, h - 1),
			cv::Scalar(0, 0, 0), 1, CV_AA, 0);
	cv::line(img, cv::Point2i(w - 1, h - 1), cv::Point2i(w - 1, 0),
			cv::Scalar(0, 0, 0), 1, CV_AA, 0);
	cv::line(img, cv::Point2i(w - 1, 0), cv::Point2i(0, 0), cv::Scalar(0, 0, 0),
			1, CV_AA, 0);
	CvMat cvImg = img;
	cvFlip(&cvImg, 0);
	cv::imwrite(filePath, img);
	delete[] imgData;
}
Example #11
0
void VIICanvas::OpenGLInit()
{
	static bool onInit = true;
	
	//wxGLCanvas::SetCurrent(*mContext);
	//wxPaintDC(this);
	
	if(onInit)
	{
		this->mWidth = (GLint)GetSize().x;//1024;
		this->mHeight = (GLint)GetSize().y;//768
	
		std::cout << "Initialisiere OpenGL"<<std::endl;
		wxGLCanvas::SetCurrent(*mContext);
		wxPaintDC(this);
		
		glClearColor(1.0,1.0,1.0,0.0);
		//glClearColor(0.0,0.0,0.0,0.0);
		//glClear(GL_COLOR_BUFFER_BIT);
		glViewport(0,0,(GLint)GetSize().x,(GLint)GetSize().y);
		changeProjectionMode(true);
		onInit = false;
	}
}
Example #12
0
 //本当は再描画のことも考えた関数設計にする
void AGIPane::render(wxPaintEvent& evt)
{
	std::cerr << "AGIRender" << std::endl;
    if(!IsShown()) return;
 
    wxGLCanvas::SetCurrent(*m_context);
    wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event
 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    const int atr = data->atr;
    std::list<int> notselected = data->getNSIndex();
    const int num = data->num;
    const int width = getWidth();
    // ------------- draw some 2D ----------------
    prepare2DViewport(0, 0, width, width);
    glLoadIdentity();
 
    //white background
    glColor4f(1, 1, 1, 1);
    glBegin(GL_QUADS);
    glVertex3f(0, 0, 0);
    glVertex3f(width, 0, 0);
    glVertex3f(width, width, 0);
    glVertex3f(0, width, 0);
    glEnd();
   
    //辺を描く
    glColor4f(0.2f, 0.4f, 0.7f, 0.3f);
    glLineWidth(1);
	glBegin(GL_LINES);
	std::vector<std::pair<int,int> > edge = data->filteredge;
	for(int i = 0;i< edge.size();i++){
		int n1 = edge.at(i).first;
		int n2 = edge.at(i).second;
		glVertex3f(enlarge(ag->getB(n1,0)), enlarge(ag->getB(n1,1)),0);
		glVertex3f(enlarge(ag->getB(n2,0)), enlarge(ag->getB(n2,1)),0);
	}
    glEnd();
     glColor4f(0.2f, 0.4f, 0.7f, 1.0f);
    glPointSize(5.0);
    glBegin(GL_POINTS);
    //選択されていない点を書く
  	for(int i: notselected){
       	glVertex3f(enlarge(ag->getB(i,0)), enlarge(ag->getB(i,1)),0);
    }
    glEnd();
    glPointSize(8.0); 
    glBegin(GL_POINTS);
    //選択されている点を描く
    for(auto c:data->getCluster()){
    	RGB rgb = c.rgb; 
    	glColor4f(rgb.r, rgb.g, rgb.b, 1.0f);
    	for(int i :c.index ){ 
       		glVertex3f(enlarge(ag->getB(i,0)), enlarge(ag->getB(i,1)), 0);
    	}
	}
	glEnd();
	if(data->isPCA){
		//元の軸を描く
		glLineWidth(2.0);
		glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
		glBegin(GL_LINES);
		for(int i = 0;i< atr;i++){ 
			drawaxispca(i);
		}
		glEnd();
		//PCPが軸選択モードのとき
		if(data->isCoord){
			int o = data->selectedorder;
			glColor4f(0.8f, 0.1f, 0.1f, 1.0f);
			glLineWidth(2.0);
			glBegin(GL_LINES);	
			drawaxispca(data->order[o]);
			glEnd();
			glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
			int from = std::max(o-1,0);
			int to = std::min(o+2,atr);
			for(int i = from;i< to;i++){
				int k = data->order[i];
				drawcoodname(k);
			}		
		}
		else{
			for(int i = 0;i< atr;i++)
				drawcoodname(i);
    	}
    	//agiで軸選択がされているとき
    	int nowcoord = data->selectedcoord;
    	if(nowcoord != -1){
    		glColor4f(0.8f, 0.1f, 0.1f, 1.0f);
			glBegin(GL_LINES);	
			drawaxispca(nowcoord);
			glEnd();
			drawcoodname(nowcoord);
    	}
    	glLineWidth(1);
	}
	//pcaを使っていないとき
	else{
		glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
		glPointSize(5.0);
		glLineWidth(1);
		for(int i = 0; i<data->atr ;i++){
			glBegin(GL_POINTS);
			int x = enlarge(ag->getB(i+num,0));
			int y = enlarge(ag->getB(i+num,1));
			glVertex3f(x, y, 0);
			glEnd();
			
			glRasterPos2d(x+5, y+5);
    		std::string str = data->atrname.at(i);
   			int size = (int)str.size();
    		for(int j = 0;j< size;j++){
       			char ic = str[j];
        		glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24,ic);
    		} 
    		glBegin(GL_LINES);
    		glVertex3f(width/2,width/2,0);
    		glVertex3f(x,y,0);
    		glEnd();  		
		}
		glLineWidth(1);
	}
	//範囲選択がされているとき
    if(rangeselect){
    	glColor4f(0.0f,0.0f,0.0f,1.0f);
    	glBegin(GL_LINE_STRIP);
    	glVertex3f(xfrom,yfrom,0);
    	glVertex3f(xfrom,yto,0);
    	glVertex3f(xto,yto,0);
    	glVertex3f(xto,yfrom,0);
    	glVertex3f(xfrom,yfrom,0);
    	glEnd();
    }
    if(polystart){
    	glColor4f(0.0f,0.0f,0.0f,1.0f);
    	glBegin(GL_LINE_LOOP);
    	for(auto p:polyvector)
    		glVertex3f(p.first,p.second,0);
    	glVertex3f(polynow.first,polynow.second,0);
    	glEnd();
    }
    glFlush();
    SwapBuffers();
}
Example #13
0
void CCodeView::OnPaint(wxPaintEvent& event)
{
  // -------------------------
  // General settings
  // -------------------------
  std::unique_ptr<wxGraphicsContext> ctx(wxGraphicsContext::Create(wxPaintDC(this)));
  wxRect rc = GetClientRect();

  ctx->SetFont(DebuggerFont, *wxBLACK);

  wxDouble w, h;
  ctx->GetTextExtent("0WJyq", &w, &h);

  if (h > m_rowHeight)
    m_rowHeight = h;

  ctx->GetTextExtent("W", &w, &h);
  int charWidth = w;

  struct branch
  {
    int src, dst, srcAddr;
  };

  branch branches[256];
  int numBranches = 0;
  // TODO: Add any drawing code here...
  int width = rc.width;
  int numRows = ((rc.height / m_rowHeight) / 2) + 2;
  // ------------

  // -------------------------
  // Colors and brushes
  // -------------------------

  const wxColour bgColor = *wxWHITE;
  wxPen nullPen(bgColor);
  wxPen currentPen(*wxBLACK_PEN);
  wxPen selPen(*wxGREY_PEN);
  nullPen.SetStyle(wxPENSTYLE_TRANSPARENT);
  currentPen.SetStyle(wxPENSTYLE_SOLID);
  wxBrush currentBrush(*wxLIGHT_GREY_BRUSH);
  wxBrush pcBrush(*wxGREEN_BRUSH);
  wxBrush bpBrush(*wxRED_BRUSH);

  wxBrush bgBrush(bgColor);
  wxBrush nullBrush(bgColor);
  nullBrush.SetStyle(wxBRUSHSTYLE_TRANSPARENT);

  ctx->SetPen(nullPen);
  ctx->SetBrush(bgBrush);
  ctx->DrawRectangle(0, 0, 16, rc.height);
  ctx->DrawRectangle(0, 0, rc.width, 5);
  // ------------

  // -----------------------------
  // Walk through all visible rows
  // -----------------------------
  for (int i = -numRows; i <= numRows; i++)
  {
    unsigned int address = m_curAddress + (i * m_align);

    int rowY1 = (rc.height / 2) + (m_rowHeight * i) - (m_rowHeight / 2);
    int rowY2 = (rc.height / 2) + (m_rowHeight * i) + (m_rowHeight / 2);

    wxString temp = wxString::Format("%08x", address);
    u32 color = m_debugger->GetColor(address);
    wxBrush rowBrush(wxColour(color >> 16, color >> 8, color));
    ctx->SetBrush(nullBrush);
    ctx->SetPen(nullPen);
    ctx->DrawRectangle(0, rowY1, 16, rowY2 - rowY1 + 2);

    if (m_selecting && (address == m_selection))
      ctx->SetPen(selPen);
    else
      ctx->SetPen(i == 0 ? currentPen : nullPen);

    if (address == m_debugger->GetPC())
      ctx->SetBrush(pcBrush);
    else
      ctx->SetBrush(rowBrush);

    ctx->DrawRectangle(16, rowY1, width, rowY2 - rowY1 + 1);
    ctx->SetBrush(currentBrush);
    if (!m_plain)
    {
      // the address text is dark red
      ctx->SetFont(DebuggerFont, wxColour("#600000"));
      ctx->DrawText(temp, 17, rowY1);
      ctx->SetFont(DebuggerFont, *wxBLACK);
    }

    // If running
    if (m_debugger->IsAlive())
    {
      std::vector<std::string> dis;
      SplitString(m_debugger->Disassemble(address), '\t', dis);
      dis.resize(2);

      static const size_t VALID_BRANCH_LENGTH = 10;
      const std::string& opcode = dis[0];
      const std::string& operands = dis[1];
      std::string desc;

      // look for hex strings to decode branches
      std::string hex_str;
      size_t pos = operands.find("0x8");
      if (pos != std::string::npos)
      {
        hex_str = operands.substr(pos);
      }

      if (hex_str.length() == VALID_BRANCH_LENGTH)
      {
        u32 offs = std::stoul(hex_str, nullptr, 16);

        branches[numBranches].src = rowY1 + (m_rowHeight / 2);
        branches[numBranches].srcAddr = (address / m_align);
        branches[numBranches++].dst =
            (int)(rowY1 + ((s64)(u32)offs - (s64)(u32)address) * m_rowHeight / m_align +
                  m_rowHeight / 2);
        desc = StringFromFormat("-->%s", m_debugger->GetDescription(offs).c_str());

        // the -> arrow illustrations are purple
        ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("PURPLE"));
      }
      else
      {
        ctx->SetFont(DebuggerFont, *wxBLACK);
      }

      ctx->DrawText(StrToWxStr(operands), 17 + 17 * charWidth, rowY1);
      // ------------

      // Show blr as its' own color
      if (opcode == "blr")
        ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("DARK GREEN"));
      else
        ctx->SetFont(DebuggerFont, wxTheColourDatabase->Find("VIOLET"));

      ctx->DrawText(StrToWxStr(opcode), 17 + (m_plain ? 1 * charWidth : 9 * charWidth), rowY1);

      if (desc.empty())
      {
        desc = m_debugger->GetDescription(address);
      }

      if (!m_plain)
      {
        ctx->SetFont(DebuggerFont, *wxBLUE);

        // char temp[256];
        // UnDecorateSymbolName(desc,temp,255,UNDNAME_COMPLETE);
        if (!desc.empty())
        {
          ctx->DrawText(StrToWxStr(desc), 17 + 35 * charWidth, rowY1);
        }
      }

      // Show red breakpoint dot
      if (m_debugger->IsBreakpoint(address))
      {
        ctx->SetBrush(bpBrush);
        ctx->DrawRectangle(2, rowY1 + 1, 11, 11);
      }
    }
  }  // end of for
  // ------------

  // -------------------------
  // Colors and brushes
  // -------------------------
  ctx->SetPen(currentPen);

  for (int i = 0; i < numBranches; i++)
  {
    int x = 17 + 49 * charWidth + (branches[i].srcAddr % 9) * 8;
    MoveTo(x - 2, branches[i].src);

    if (branches[i].dst < rc.height + 400 && branches[i].dst > -400)
    {
      LineTo(ctx, x + 2, branches[i].src);
      LineTo(ctx, x + 2, branches[i].dst);
      LineTo(ctx, x - 4, branches[i].dst);

      MoveTo(x, branches[i].dst - 4);
      LineTo(ctx, x - 4, branches[i].dst);
      LineTo(ctx, x + 1, branches[i].dst + 5);
    }
    // else
    //{
    // This can be re-enabled when there is a scrollbar or
    // something on the codeview (the lines are too long)

    // LineTo(ctx, x+4, branches[i].src);
    // MoveTo(x+2, branches[i].dst-4);
    // LineTo(ctx, x+6, branches[i].dst);
    // LineTo(ctx, x+1, branches[i].dst+5);
    //}

    // LineTo(ctx, x, branches[i].dst+4);
    // LineTo(ctx, x-2, branches[i].dst);
  }
  // ------------
}
Example #14
0
void GSFrame::OnPaint(wxPaintEvent& event)
{
	wxPaintDC(this);
}
Example #15
0
void BasicCanvas::OnPaint(wxPaintEvent &event) {
	wxPaintDC(this);
	this->Render();
}
Example #16
0
void SubtitlesPreview::OnPaint(wxPaintEvent &) {
	wxPaintDC(this).DrawBitmap(*bmp, 0, 0);
}
void GLImagePane::draw() {
	MyApp::bBusyDrawingVideo[m_camId] = true;
	wxGLCanvas::SetCurrent(*m_context);
	wxPaintDC(this); // only to be used in paint events. use wxClientDC to paint outside the paint event

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// ------------- draw some 2D ----------------
	prepare2DViewport(0, 0, getWidth(), getHeight());
	glLoadIdentity();

	//draw video frame
	if (imgData) {
		glEnable(GL_TEXTURE_2D);
		if (b_firstRun) {
			glGenTextures(1, &m_imgTexture); // generate OpenGL texture object
			glBindTexture(GL_TEXTURE_2D, m_imgTexture); // use previously created texture object and set options
			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
			b_firstRun = false;
		}
		if (s_clicked_camid >= 0) {
			ImgRGB img(imgWidth, imgHeight);
			gray2rgb(imgWidth, imgHeight, imgData, img.data);
			drawClickedPoint(img);
			if (s_clicked_camid != m_camId)
				drawEpipolarLine(img);
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
					GL_RGB, GL_UNSIGNED_BYTE, img.data);
		} else
			glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
					GL_LUMINANCE, GL_UNSIGNED_BYTE, imgData);

		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex3f(0, 0, 0);
		glTexCoord2f(1, 0);
		glVertex3f(getWidth(), 0, 0);
		glTexCoord2f(1, 1);
		glVertex3f(getWidth(), getHeight(), 0);
		glTexCoord2f(0, 1);
		glVertex3f(0, getHeight(), 0);
		glEnd();
		glDisable(GL_TEXTURE_2D);
	} else {
		// white background
		glColor4f(1, 1, 1, 1);
		glBegin(GL_QUADS);
		glVertex3f(0, 0, 0);
		glVertex3f(getWidth(), 0, 0);
		glVertex3f(getWidth(), getHeight(), 0);
		glVertex3f(0, getHeight(), 0);
		glEnd();
	}

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_POINT_SMOOTH);
	glEnable(GL_LINE_SMOOTH);
	glEnable(GL_POLYGON_SMOOTH);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);

	drawFeaturePoints();

	if (imgData) {
		drawConvexHulls();
		drawInfo(0, 0, getWidth(), getHeight());
	}

	SwapBuffers();
	MyApp::bBusyDrawingVideo[m_camId] = false;
}
Example #18
0
void RadarCanvas::Render(wxPaintEvent &evt) {
  int w, h;

  if (!IsShown() || !m_pi->m_initialized) {
    return;
  }

  GetClientSize(&w, &h);
  wxPaintDC(this);  // only to be used in paint events. use wxClientDC to paint
                    // outside the paint event

  if (!m_pi->m_opengl_mode) {
    LOG_DIALOG(wxT("BR24radar_pi: %s cannot render non-OpenGL mode"), m_ri->m_name.c_str());
    return;
  }
  if (!m_pi->m_opencpn_gl_context && !m_pi->m_opencpn_gl_context_broken) {
    LOG_DIALOG(wxT("BR24radar_pi: %s skip render as no context known yet"), m_ri->m_name.c_str());
    return;
  }
  LOG_DIALOG(wxT("BR24radar_pi: %s render OpenGL canvas %d by %d "), m_ri->m_name.c_str(), w, h);

  SetCurrent(*m_context);

  glPushMatrix();
  glPushAttrib(GL_ALL_ATTRIB_BITS);

  wxFont font = GetOCPNGUIScaledFont_PlugIn(_T("StatusBar"));
  m_FontNormal.Build(font);
  wxFont bigFont = GetOCPNGUIScaledFont_PlugIn(_T("Dialog"));
  bigFont.SetPointSize(bigFont.GetPointSize() + 2);
  bigFont.SetWeight(wxFONTWEIGHT_BOLD);
  m_FontBig.Build(bigFont);
  bigFont.SetPointSize(bigFont.GetPointSize() + 2);
  bigFont.SetWeight(wxFONTWEIGHT_NORMAL);
  m_FontMenu.Build(bigFont);
  bigFont.SetPointSize(bigFont.GetPointSize() + 10);
  bigFont.SetWeight(wxFONTWEIGHT_BOLD);
  m_FontMenuBold.Build(bigFont);

  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);                // Black Background
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  // Clear the canvas
  glEnable(GL_TEXTURE_2D);                             // Enable textures
  glEnable(GL_COLOR_MATERIAL);
  glEnable(GL_BLEND);
  // glDisable(GL_DEPTH_TEST);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);  // Next two operations on the project matrix stack
  glLoadIdentity();             // Reset projection matrix stack
  glOrtho(0, w, h, 0, -1, 1);
  glMatrixMode(GL_MODELVIEW);  // Reset matrick stack target back to GL_MODELVIEW

  RenderRangeRingsAndHeading(w, h);
  Render_EBL_VRM(w, h);

  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);  // Next two operations on the project matrix stack
  glLoadIdentity();             // Reset projection matrix stack
  if (w >= h) {
    glScaled(1.0, (float)-w / h, 1.0);
  } else {
    glScaled((float)h / w, -1.0, 1.0);
  }
  glMatrixMode(GL_MODELVIEW);  // Reset matrick stack target back to GL_MODELVIEW

  m_ri->RenderRadarImage(wxPoint(0, 0), 1.0, 0.0, false);

  glViewport(0, 0, w, h);
  glMatrixMode(GL_PROJECTION);  // Next two operations on the project matrix stack
  glLoadIdentity();             // Reset projection matrix stack
  glOrtho(0, w, h, 0, -1, 1);
  glMatrixMode(GL_MODELVIEW);  // Reset matrick stack target back to GL_MODELVIEW

  glEnable(GL_TEXTURE_2D);

  RenderTexts(w, h);
  RenderCursor(w, h);

#ifdef NEVER
  glDisable(GL_TEXTURE_2D);

  glMatrixMode(GL_PROJECTION);  // Next two operations on the project matrix stack
  glLoadIdentity();             // Reset projection matrix stack
  glMatrixMode(GL_MODELVIEW);   // Reset matrick stack target back to GL_MODELVIEW
#endif

  glPopAttrib();
  glPopMatrix();
  glFlush();
  glFinish();
  SwapBuffers();

  if (m_pi->m_opencpn_gl_context) {
    SetCurrent(*m_pi->m_opencpn_gl_context);
  } else {
    SetCurrent(*m_zero_context);  // Make sure OpenCPN -at least- doesn't overwrite our context info
  }
}
void C3D_MODEL_VIEWER::OnPaint( wxPaintEvent &event )
{
    wxPaintDC( this );

    // SwapBuffer requires the window to be shown before calling
    if( !IsShownOnScreen() )
    {
        wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint !IsShown" ) );
        return;
    }

    // "Makes the OpenGL state that is represented by the OpenGL rendering
    //  context context current, i.e. it will be used by all subsequent OpenGL calls.
    //  This function may only be called when the window is shown on screen"
    GL_CONTEXT_MANAGER::Get().LockCtx( m_glRC, this );

    // Set the OpenGL viewport according to the client size of this canvas.
    // This is done here rather than in a wxSizeEvent handler because our
    // OpenGL rendering context (and thus viewport setting) is used with
    // multiple canvases: If we updated the viewport in the wxSizeEvent
    // handler, changing the size of one canvas causes a viewport setting that
    // is wrong when next another canvas is repainted.
    wxSize clientSize = GetClientSize();

    if( !m_ogl_initialized )
    {
        m_ogl_initialized = true;
        ogl_initialize();
    }

    if( m_reload_is_needed )
    {
        wxLogTrace( m_logTrace, wxT( "C3D_MODEL_VIEWER::OnPaint m_reload_is_needed" ) );

        m_reload_is_needed = false;
        m_ogl_3dmodel = new C_OGL_3DMODEL( *m_3d_model );

        // It convert a model as it was a board, so get the max size dimension of the board
        // and compute the conversion scale
        m_BiuTo3Dunits = (double)RANGE_SCALE_3D / ((double)m_ogl_3dmodel->GetBBox().GetMaxDimension() * UNITS3D_TO_UNITSPCB);
    }

    glViewport( 0, 0, clientSize.x, clientSize.y );

    m_trackBallCamera.SetCurWindowSize( clientSize );

    // clear color and depth buffers
    // /////////////////////////////////////////////////////////////////////////
    glEnable( GL_DEPTH_TEST );

    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glClearDepth( 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Set projection and modelview matrixes
    // /////////////////////////////////////////////////////////////////////////
    glMatrixMode( GL_PROJECTION );
    glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetProjectionMatrix() ) );

    glMatrixMode( GL_MODELVIEW );
    glLoadMatrixf( glm::value_ptr( m_trackBallCamera.GetViewMatrix() ) );

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    // Render Model
    if( m_ogl_3dmodel )
    {
        glPushMatrix();

        double modelunit_to_3d_units_factor = m_BiuTo3Dunits * UNITS3D_TO_UNITSPCB;

        glScaled( modelunit_to_3d_units_factor, modelunit_to_3d_units_factor, modelunit_to_3d_units_factor);

        // Center model in the render viewport
        const SFVEC3F model_center = m_ogl_3dmodel->GetBBox().GetCenter();
        glTranslatef( -model_center.x, -model_center.y, -model_center.z );

        // !TODO: draw transparent models
        m_ogl_3dmodel->Draw_opaque();
        m_ogl_3dmodel->Draw_transparent();
        //m_ogl_3dmodel->Draw_bboxes();

        glPopMatrix();
    }


    glViewport( 0, 0, clientSize.y / 8 , clientSize.y / 8 );                    // YxY squared view port
    glClear( GL_DEPTH_BUFFER_BIT );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45.0f, 1.0f, 0.01f, RANGE_SCALE_3D * 2.0f );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    const glm::mat4 TranslationMatrix = glm::translate( glm::mat4(1.0f), SFVEC3F( 0.0f, 0.0f, -RANGE_SCALE_3D ) );
    const glm::mat4 ViewMatrix = TranslationMatrix * m_trackBallCamera.GetRotationMatrix();

    glLoadMatrixf( glm::value_ptr( ViewMatrix ) );

    ogl_set_arrow_material();

    glColor3f( 0.9f, 0.0f, 0.0f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( RANGE_SCALE_3D / 2.65f, 0.0f, 0.0f ),
                    0.275f );

    glColor3f( 0.0f, 0.9f, 0.0f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( 0.0f, RANGE_SCALE_3D / 2.65f, 0.0f ),
                    0.275f );

    glColor3f( 0.0f, 0.0f, 0.9f );
    OGL_draw_arrow( SFVEC3F( 0.0f, 0.0f, 0.0f ),
                    SFVEC3F( 0.0f, 0.0f, RANGE_SCALE_3D / 2.65f ),
                    0.275f );

    // "Swaps the double-buffer of this window, making the back-buffer the
    //  front-buffer and vice versa, so that the output of the previous OpenGL
    //  commands is displayed on the window."
    SwapBuffers();
    GL_CONTEXT_MANAGER::Get().UnlockCtx( m_glRC );

    event.Skip();
}
Example #20
0
void ggscfg_ColorEditSheet::on_paint_palette(wxPaintEvent& event) {
  draw_palette(&wxPaintDC((wxWindow*)event.GetEventObject()));
}
Example #21
0
void ggscfg_ColorEditSheet::on_paint_sprite(wxPaintEvent& event) {
  draw_image(&wxPaintDC((wxWindow*)event.GetEventObject()), false);
}