Skip to main content
gamedev.net
🔒 Locked

quick question

Started by zelda6486 1 reply 550+ views
Original Post
zelda6486
zelda6486
i called glGetString(GL_RENDERER) and got "GDI generic". Does this mean its hardware accelerated or is it using the software emulation?
ANSI2000
ANSI2000
Your are probably setting the pixe format wrong here is what i do...


#ifndef G3DRENDERER_H
#define G3DRENDERER_H

// Required include files.
#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <gl/gl.h>
#include <gl/glu.h>

class G3DRenderer
{
public:

G3DRenderer(HDC pDeviceContext, int pWidth, int pHeight, int pBpp = 32, int pZBpp = 32, int pSBpp = 32)
: deviceContext(pDeviceContext), width(pWidth), height(pHeight), bpp(pBpp), zBpp(pZBpp), sBpp(pSBpp)
{
setPixelFormat(bpp, zBpp, sBpp);
setRenderingContext();
setViewPort(width, height);
}

~G3DRenderer() {}

void setPixelFormat(int pBpp = 32, int pZBpp = 32, int pSBpp = 32)
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof (PIXELFORMATDESCRIPTOR),
1, // Version Number
PFD_DRAW_TO_WINDOW | // Support Window
PFD_SUPPORT_OPENGL | // Support OpenGL
PFD_DOUBLEBUFFER, // Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
pBpp, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits
0, // Alpha Buffer
0, // Shift Bit Ignored
0, // Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits
pZBpp, // Depth Buffer
pSBpp, // Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks
};

pixelFormat = ChoosePixelFormat (deviceContext, &pfd);

if(pixelFormat == 0)
{
MessageBox(NULL, "Could not pick pixel format.", "Error", NULL);
}

if(SetPixelFormat (deviceContext, pixelFormat, &pfd) == FALSE)
{
MessageBox(NULL, "Failed to set pixel format.", "Error", NULL);
}
}

void getVendorInfo(char *pVendorInfo)
{
sprintf(pVendorInfo, "\nVendor: %s\nOpenGL: %s\nRenderer: %s\n", (char *)glGetString(GL_VENDOR), (char *)glGetString(GL_VERSION), (char *)glGetString(GL_RENDERER));
}

void setRenderingContext()
{
renderingContext = wglCreateContext (deviceContext);

if (renderingContext == 0)
{
MessageBox(NULL, "Failed to create rendering context.", "Error", NULL);
}

if (wglMakeCurrent (deviceContext, renderingContext) == FALSE)
{
MessageBox(NULL, "Failed to set rendering context.", "Error", NULL);
}
}

void setViewPort(int pWidth, int pHeight)
{
width = pWidth;
height = pHeight;

glViewport (0, 0, (GLsizei)(width), (GLsizei)(height));
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)(width)/(GLfloat)(height), 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

BOOL initialize()
{
// Start Of User Initialization
angle = 0.0f; // Set Starting Angle To Zero

glClearColor (0.0f, 0.0f, 1.0f, 0.0f); // Black Background
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glEnable (GL_DEPTH_TEST); // Enable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate

return(true);
}

void update()
{
angle += (float)0.1f;
}


void draw()
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity (); // Reset The Modelview Matrix
glTranslatef (0.0f, 0.0f, -6.0f); // Translate 6 Units Into The Screen
glRotatef (angle, 0.0f, 1.0f, 0.0f); // Rotate On The Y-Axis By angle

for (rot1=0; rot1<2; rot1++) // 2 Passes
{
glRotatef(90.0f,0.0f,1.0f,0.0f); // Rotate 90 Degrees On The Y-Axis
glRotatef(180.0f,1.0f,0.0f,0.0f); // Rotate 180 Degress On The X-Axis
for (rot2=0; rot2<2; rot2++) // 2 Passes
{
glRotatef(180.0f,0.0f,1.0f,0.0f); // Rotate 180 Degrees On The Y-Axis
glBegin (GL_TRIANGLES); // Begin Drawing Triangles
glColor3f (1.f, 0.f, 0.f); glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f (0.f, 1.f, 0.f); glVertex3f(-1.0f,-1.0f, 1.0f);
glColor3f (0.f, 0.f, 1.f); glVertex3f( 1.0f,-1.0f, 1.0f);
glEnd (); // Done Drawing Triangles
}
}

SwapBuffers (deviceContext); // Swap Buffers (Double Buffering)

glFlush (); // Flush The GL Rendering Pipeline
}

private:

HDC deviceContext;
HGLRC renderingContext;
int width; // Screen/Viewport width
int height; // Screen/Viewport height
int bpp; // Bits per pixel
int zBpp; // Bits per pixel
int sBpp; // Stencil Buffer bits per pixel
unsigned int pixelFormat;

// User Defined Variables
float angle; // Used To Rotate The Triangles
int rot1, rot2; // Counter Variables

};


The initialze, update and draw methods are there for quick testing...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.