Example #1
0
Terrain::Terrain(Eigen::Vector2f a_size, Eigen::Vector2i a_res, int n_hill, TerrainType a_type){
	m_type = TypeTerrain;
	m_frictness = 10;
	
	InitBase(a_size.x(), a_size.y(), a_res.x(), a_res.y(), n_hill, a_type);

	InitDraw();
}
Example #2
0
void Cube::Init(Eigen::Vector3f center, Eigen::Vector3f scale, Eigen::Vector3f color){

    m_Center = center;
    m_Size = scale;
	m_Color = color;
    
	m_Trans.setIdentity();
	m_Trans.translate(m_Center);
    m_Trans.scale(m_Size);
    
    m_TransBack = m_Trans.inverse();

	InitDraw();
}
Example #3
0
/* A general OpenGL initialization function.  Sets all of the initial parameters. */
void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
	glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
	glDepthFunc(GL_GREATER); // The Type Of Depth Test To Do
	glEnable(GL_DEPTH_TEST); // Enables Depth Testing
	glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity(); // Reset The Projection Matrix

	gluPerspective(30.0f, (GLfloat) Width / (GLfloat) Height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window

	glMatrixMode(GL_MODELVIEW);

	//http://cirl.missouri.edu/gpu/glsl_lessons/glsl_geometry_shader/index.html

	setShaders(&ProgramObject);

	//http://www.opengl.org/wiki/Texture_Sampling
	//Setting shader's uniform variables
	GLint volume_location = glGetUniformLocation(ProgramObject,
			"volume_texture");
	GLint tf_location =
			glGetUniformLocation(ProgramObject, "transfer_function");

	//Checking if the state of the shader is also consider invalid.
	int isValid;
	glValidateProgram(ProgramObject);
	glGetProgramiv(ProgramObject, GL_VALIDATE_STATUS, &isValid);
	if (isValid)
		printf("Shader is valid!\n");
	else {
		printf("Shader isn't Valid!");
		exit(1);
	}

	// So, to set up those uniforms, bind the shader and call glUniform1i since they are considered as integers
	glUseProgram(ProgramObject);
	//Bind to tex unit 0
	glUniform1i(volume_location, 0);
	//Bind to tex unit 1
	glUniform1i(tf_location, 1);

	InitTexture();

	InitDraw();

}
void CGroup::CoreDraw(void)
{
    InitDraw();
    
    if (m_bUpdateLayout)
    {
        DrawLayout();
        m_bUpdateLayout = false;
    }

    DoDraw();
    RefreshWidget();

    DrawChilds();
}
Example #5
0
struct PointList* FillPolygon(struct PointListHeader * VertexList, int Color,
      int PolygonShape, int XOffset, int YOffset)
{
   struct EdgeState *EdgeTableBuffer;
   int CurrentY;

   InitDraw(); // inits point list that will be "drawn" (added) to the list

#ifdef CONVEX_CODE_LINKED
   /* Pass convex polygons through to fast convex polygon filler */
   if (PolygonShape == CONVEX)
      return(FillConvexPolygon(VertexList, Color, XOffset, YOffset));
#endif

   /* It takes a minimum of 3 vertices to cause any pixels to be
      drawn; reject polygons that are guaranteed to be invisible */
   if (VertexList->Length < 3)
      return(0);
   /* Get enough memory to store the entire edge table */
   if ((EdgeTableBuffer =
         (struct EdgeState *) (malloc(sizeof(struct EdgeState) *
         VertexList->Length))) == NULL)
      return(0);  /* couldn't get memory for the edge table */
   /* Build the global edge table */
   BuildGET(VertexList, EdgeTableBuffer, XOffset, YOffset);
   /* Scan down through the polygon edges, one scan line at a time,
      so long as at least one edge remains in either the GET or AET */
   AETPtr = NULL;    /* initialize the active edge table to empty */
   CurrentY = GETPtr->StartY; /* start at the top polygon vertex */
   while ((GETPtr != NULL) || (AETPtr != NULL)) {
      MoveXSortedToAET(CurrentY);  /* update AET for this scan line */
      ScanOutAET(CurrentY, Color); /* draw this scan line from AET */
      AdvanceAET();                /* advance AET edges 1 scan line */
      XSortAET();                  /* resort on X */
      CurrentY++;                  /* advance to the next scan line */
   }
   /* Release the memory we've allocated and we're done */
   free(EdgeTableBuffer);
   return(pointListTop);
}
Example #6
0
    /*
     *  ウインドウ作成
     */
void OnCreate(AG_Widget *parent)
{
        BOOL        flag;
/*
 * ワークエリア初期化
 */
        nErrorCode = 0;
        bMenuLoop = FALSE;
        bCloseReq = FALSE;
        bSync = TRUE;
        bSyncDisasm[0] = TRUE;
        bSyncDisasm[1] = TRUE;
        bActivate = FALSE;
        AG_MutexInit(&VMMutex);
/*
 * コンポーネント初期化
 */
        LoadCfg();
        InitDraw();
#ifdef _USE_OPENCL
        if(AG_UsingGL(NULL) != 0) {
	   do {
	       SDL_Delay(1);
	   } while(bInitCL);
	}
#endif   
        InitSnd();
        InitKbd();
        InitJoy();
        InitSch();
//        CreateStatus();

/*
 * 仮想マシン初期化
 */
        if (!system_init()) {
                nErrorCode = 1;
                return;
        }
/*
 * 直後、リセット
 */
        ApplyCfg();
        system_reset();

/*
 * コンポーネントセレクト
 */
        flag = TRUE;
        if (!SelectDraw()) {
                flag = FALSE;
        }
        if (!SelectSnd()) {
                flag = FALSE;
        }
        if (!SelectKbd()) {
                flag = FALSE;
        }
        if (!SelectSch()) {
                flag = FALSE;
        }
        PaintStatus();

/*
 * エラーコードをセットさせ、スタート
 */
        if (!flag) {
                nErrorCode = 2;
        }
}
Example #7
0
//////////////////////////////////////////////////////////////////////////
/// @brief DrawIndexedInstanced
/// @param hContext - Handle passed back from SwrCreateContext
/// @param topology - Specifies topology for draw.
/// @param numIndices - Number of indices to read sequentially from index buffer.
/// @param indexOffset - Starting index into index buffer.
/// @param baseVertex - Vertex in vertex buffer to consider as index "0". Note value is signed.
/// @param numInstances - Number of instances to render.
/// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
void DrawIndexedInstance(
    HANDLE hContext,
    PRIMITIVE_TOPOLOGY topology,
    uint32_t numIndices,
    uint32_t indexOffset,
    int32_t baseVertex,
    uint32_t numInstances = 1,
    uint32_t startInstance = 0)
{
    RDTSC_START(APIDrawIndexed);

    SWR_CONTEXT *pContext = GetContext(hContext);
    DRAW_CONTEXT* pDC = GetDrawContext(pContext);
    API_STATE* pState = &pDC->pState->state;

    int32_t maxIndicesPerDraw = MaxVertsPerDraw(pDC, numIndices, topology);
    uint32_t primsPerDraw = GetNumPrims(topology, maxIndicesPerDraw);
    int32_t remainingIndices = numIndices;

    uint32_t indexSize = 0;
    switch (pState->indexBuffer.format)
    {
    case R32_UINT: indexSize = sizeof(uint32_t); break;
    case R16_UINT: indexSize = sizeof(uint16_t); break;
    case R8_UINT: indexSize = sizeof(uint8_t); break;
    default:
        SWR_ASSERT(0);
    }

    int draw = 0;
    uint8_t *pIB = (uint8_t*)pState->indexBuffer.pIndices;
    pIB += (uint64_t)indexOffset * (uint64_t)indexSize;

    pState->topology = topology;
    pState->forceFront = false;

    // disable culling for points/lines
    uint32_t oldCullMode = pState->rastState.cullMode;
    if (topology == TOP_POINT_LIST)
    {
        pState->rastState.cullMode = SWR_CULLMODE_NONE;
        pState->forceFront = true;
    }

    while (remainingIndices)
    {
        uint32_t numIndicesForDraw = (remainingIndices < maxIndicesPerDraw) ?
        remainingIndices : maxIndicesPerDraw;

        // When breaking up draw, we need to obtain new draw context for each iteration.
        bool isSplitDraw = (draw > 0) ? true : false;
        pDC = GetDrawContext(pContext, isSplitDraw);
        InitDraw(pDC, isSplitDraw);

        pDC->FeWork.type = DRAW;
        pDC->FeWork.pfnWork = GetFEDrawFunc(
            true,   // IsIndexed
            pState->tsState.tsEnable,
            pState->gsState.gsEnable,
            pState->soState.soEnable,
            pDC->pState->pfnProcessPrims != nullptr);
        pDC->FeWork.desc.draw.pDC = pDC;
        pDC->FeWork.desc.draw.numIndices = numIndicesForDraw;
        pDC->FeWork.desc.draw.pIB = (int*)pIB;
        pDC->FeWork.desc.draw.type = pDC->pState->state.indexBuffer.format;

        pDC->FeWork.desc.draw.numInstances = numInstances;
        pDC->FeWork.desc.draw.startInstance = startInstance;
        pDC->FeWork.desc.draw.baseVertex = baseVertex;
        pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw;

        //enqueue DC
        QueueDraw(pContext);

        pIB += maxIndicesPerDraw * indexSize;
        remainingIndices -= numIndicesForDraw;
        draw++;
    }

    // restore culling state
    pDC = GetDrawContext(pContext);
    pDC->pState->state.rastState.cullMode = oldCullMode;

    RDTSC_STOP(APIDrawIndexed, numIndices * numInstances, 0);
}
Example #8
0
//////////////////////////////////////////////////////////////////////////
/// @brief DrawInstanced
/// @param hContext - Handle passed back from SwrCreateContext
/// @param topology - Specifies topology for draw.
/// @param numVerts - How many vertices to read sequentially from vertex data (per instance).
/// @param startVertex - Specifies start vertex for draw. (vertex data)
/// @param numInstances - How many instances to render.
/// @param startInstance - Which instance to start sequentially fetching from in each buffer (instanced data)
void DrawInstanced(
    HANDLE hContext,
    PRIMITIVE_TOPOLOGY topology,
    uint32_t numVertices,
    uint32_t startVertex,
    uint32_t numInstances = 1,
    uint32_t startInstance = 0)
{
    RDTSC_START(APIDraw);

#if KNOB_ENABLE_TOSS_POINTS
    if (KNOB_TOSS_DRAW)
    {
        return;
    }
#endif

    SWR_CONTEXT *pContext = GetContext(hContext);
    DRAW_CONTEXT* pDC = GetDrawContext(pContext);

    int32_t maxVertsPerDraw = MaxVertsPerDraw(pDC, numVertices, topology);
    uint32_t primsPerDraw = GetNumPrims(topology, maxVertsPerDraw);
    int32_t remainingVerts = numVertices;

    API_STATE    *pState = &pDC->pState->state;
    pState->topology = topology;
    pState->forceFront = false;

    // disable culling for points/lines
    uint32_t oldCullMode = pState->rastState.cullMode;
    if (topology == TOP_POINT_LIST)
    {
        pState->rastState.cullMode = SWR_CULLMODE_NONE;
        pState->forceFront = true;
    }

    int draw = 0;
    while (remainingVerts)
    {
        uint32_t numVertsForDraw = (remainingVerts < maxVertsPerDraw) ?
        remainingVerts : maxVertsPerDraw;

        bool isSplitDraw = (draw > 0) ? true : false;
        DRAW_CONTEXT* pDC = GetDrawContext(pContext, isSplitDraw);
        InitDraw(pDC, isSplitDraw);

        pDC->FeWork.type = DRAW;
        pDC->FeWork.pfnWork = GetFEDrawFunc(
            false,  // IsIndexed
            pState->tsState.tsEnable,
            pState->gsState.gsEnable,
            pState->soState.soEnable,
            pDC->pState->pfnProcessPrims != nullptr);
        pDC->FeWork.desc.draw.numVerts = numVertsForDraw;
        pDC->FeWork.desc.draw.startVertex = startVertex + draw * maxVertsPerDraw;
        pDC->FeWork.desc.draw.numInstances = numInstances;
        pDC->FeWork.desc.draw.startInstance = startInstance;
        pDC->FeWork.desc.draw.startPrimID = draw * primsPerDraw;

        //enqueue DC
        QueueDraw(pContext);

        remainingVerts -= numVertsForDraw;
        draw++;
    }

    // restore culling state
    pDC = GetDrawContext(pContext);
    pDC->pState->state.rastState.cullMode = oldCullMode;

    RDTSC_STOP(APIDraw, numVertices * numInstances, 0);
}
void CWidget::DrawWidget()
{
    InitDraw();
    DoDraw();
    RefreshWidget();
}
Example #10
0
static void DrawResizeLineH(SplitterWnd *w, int y) {
    RectI rc;
    HDC hdc = InitDraw(w, rc);
    DrawXorBar(hdc, rc.x, y, rc.dx, 4);
    ReleaseDC(GetParent(w->hwnd), hdc);
}
Example #11
0
static void DrawResizeLineV(SplitterWnd *w, int x) {
    RectI rc;
    HDC hdc = InitDraw(w, rc);
    DrawXorBar(hdc, x, rc.y, 4, rc.dy);
    ReleaseDC(GetParent(w->hwnd), hdc);
}
Example #12
0
/**
 * An implementation of the Bresenham Line Algorithm.
 * This is the "optimized" version of drawline2d() from
 * <a href="http://en.wikipedia.org/wiki/Bresenham's_line_algorithm">Wikipedia.org</a>.
 * In this context, this method is used to "fill" the axis along the acoustic axis
 * of the sonar, as defined by the given coordinates, with their probabilities of being
 * occupied.
 *
 * NOTE! FillLine(start, end) does not necessarily return the same result as FillLine(end, start).
 */
struct PointList* FillLine(int x0, int y0, int x1, int y1)
{
    int i;
    int sx, sy;  /* step positive or negative (1 or -1) */
    int dx, dy;  /* delta (difference in X and Y between points) */
    int dx2, dy2;
    int e;
    int temp;

	InitDraw();

    dx = x1 - x0;
    sx = (dx > 0) ? 1 : -1;
    if (dx < 0)
        dx = -dx;

    dy = y1 - y0;
    sy = (dy > 0) ? 1 : -1;
    if (dy < 0)
        dy = -dy;

    dx2 = dx << 1; /* dx2 = 2 * dx */
    dy2 = dy << 1; /* dy2 = 2 * dy */

    if (dy <= dx) { /* steep */
        e = dy2 - dx;

        for (i = 0; i < dx; ++i) {
			DrawPixel( x0, y0, 0 );
			
            while (e >= 0) {
                y0 += sy;
                e -= dx2;
            }

            x0 += sx;
            e += dy2;
        }
    } 
    else {
        // swap x0 <-> y0
        temp = x0;
        x0 = y0;
        y0 = temp;

        // swap dx <-> dy
        temp = dx;
        dx = dy;
        dy = temp;

        // swap dx2 <-> dy2
        temp = dx2;
        dx2 = dy2;
        dy2 = temp;

        // swap sx <-> sy
        temp = sx;
        sx = sy;
        sy = temp;

        e = dy2 - dx;

        for (i = 0; i < dx; ++i) {
			DrawPixel( y0, x0, 0 );

            while (e >= 0) {
                y0 += sy;
                e -= dx2;
            }

            x0 += sx;
            e += dy2;
        }
    }

   return(pointListTop);
}