Note that there are some explanatory texts on larger screens.

plurals
  1. PONo error but still not displaying an object in the scenery
    primarykey
    data
    text
    <p>I have a scenery full of mountains and water developed in C. I want to add a Sun in the scenery. But the sun do not appears in the scenery. Attached below is my code. Please help me do this..</p> <pre><code>// Include files #include &lt;stdio.h&gt; #include &lt;windows.h&gt; #include &lt;gl\gl.h&gt; #include "gl/Glu.h" #include "Gl/glut.h" #include&lt;math.h&gt; #include&lt;conio.h&gt; #include "resources.h" #include "fovdemo.h" // Global variables HINSTANCE hInstance; HWND hWnd; HDC hDC; HGLRC hRC; float cam_x, cam_y, cam_z; float cam_yaw, cam_pitch; float hfov, aspect; int fovmode; bool active; static int useRGB = 1; static int useLighting = 1; static int useFog = 0; static int useDB = 1; static int useLogo = 0; static int useQuads = 1; static int tick = -1; static int moving = 1; #define GREY 0 #define RED 1 #define GREEN 2 #define BLUE 3 #define CYAN 4 #define MAGENTA 5 #define YELLOW 6 #define BLACK 7 static float lightPos[4] = {2.0, 4.0, 2.0, 1.0}; static float lightAmb[4] ={0.2, 0.2, 0.2, 1.0}; static float lightDiff[4] ={0.8, 0.8, 0.8, 1.0}; static float lightSpec[4] ={0.4, 0.4, 0.4, 1.0}; static float fogColor[4] ={0.0, 0.0, 0.0, 0.0}; static float fogIndex[1] ={0.0}; static unsigned char shadowPattern[128] = { 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, /* 50% Grey */ 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55 }; // Function prototypes LRESULT CALLBACK MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); BOOL CALLBACK DummyProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM) { return false; } float GetTime () { return (float)GetTickCount() / 1000.0f; } ///////////////////////////////////////////////////////////////////////////////////////////// // WINMAIN FUNCTION ///////////////////////////////////////////////////////////////////////////////////////////// int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { MSG msg; WNDCLASSEX wc; // Copy instance handle into global variable hInstance = hThisInstance; // Check for previous instance if (hPrevInstance) { MessageBox(NULL, "Sorry, you can only start one instance of this program at a time.", "Can't Start Program", MB_OK); return 0; } // Register window class wc.cbSize = sizeof(WNDCLASSEX); wc.lpszClassName = "FovDemoClass"; wc.lpfnWndProc = MainWndProc; wc.hInstance = hInstance; wc.hbrBackground = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); wc.style = CS_VREDRAW | CS_HREDRAW; wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = 0; if (!RegisterClassEx(&amp;wc)) return 0; // Create main window hWnd = CreateWindow("FovDemoClass", "Fov Demo", WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); //Sun Code glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(200, 300, 0.0f); static const int circle_points = 100; static const float angle = 2.0f * 3.1416f / circle_points; // this code (mostly) copied from question: glBegin(GL_POLYGON); double angle1=0.0; glVertex2d(50 * cos(0.0) , 50 * sin(0.0)); int i; for (i=0; i&lt;circle_points; i++) { glVertex2d(50 * cos(angle1), 50 *sin(angle1)); angle1 += angle; } glEnd(); glPopMatrix(); // Main message loop while (GetMessage(&amp;msg, NULL, 0, 0)) { TranslateMessage(&amp;msg); DispatchMessage(&amp;msg); } return msg.wParam; } ///////////////////////////////////////////////////////////////////////////////////////////// // MAINWNDPROC FUNCTION ///////////////////////////////////////////////////////////////////////////////////////////// LRESULT CALLBACK MainWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static POINT mousepos; static float last_frame_time; switch (message) { case WM_CREATE: { HWND hWndLoading; PIXELFORMATDESCRIPTOR pfd; int nBestMatch; // Show loading dialog box SetCursor(LoadCursor(NULL, IDC_WAIT)); hWndLoading = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_LOADING), hWnd, DummyProc); ShowWindow(hWndLoading, SW_SHOWNORMAL); UpdateWindow(hWndLoading); // Get window DC hDC = GetDC(hWnd); // Set up the OpenGL pixel format for this window memset(&amp;pfd, 0, sizeof(PIXELFORMATDESCRIPTOR)); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; pfd.iPixelType = PFD_TYPE_RGBA; pfd.cColorBits = 32; pfd.cDepthBits = 32; nBestMatch = ChoosePixelFormat(hDC, &amp;pfd); SetPixelFormat(hDC, nBestMatch, &amp;pfd); // Set up OpenGL hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); OpenGL_Init(); // Get rid of loading dialog SetCursor(LoadCursor(NULL, IDC_ARROW)); DestroyWindow(hWndLoading); last_frame_time = GetTime(); active = true; fovmode = FF_NORMAL; aspect = (float)GetSystemMetrics(SM_CXSCREEN) / GetSystemMetrics(SM_CYSCREEN); hfov = 90.0f; return 0; } case WM_ACTIVATE: { if (LOWORD(wParam) == WA_INACTIVE) { active = false; ShowWindow(hWnd, SW_MINIMIZE); // Minimize when alt-tabbed away, since it's a fullscreen window } else { active = true; last_frame_time = GetTime(); InvalidateRect(hWnd, NULL, false); } return 0; } case WM_PAINT: { if (active) { // Calculate time it took to draw last frame float current_time = GetTime(); float frametime = current_time - last_frame_time; last_frame_time = current_time; // Handle input, logic, whatnot OpenGL_Logic(frametime); // Render the scene OpenGL_SetupView(fovmode); OpenGL_Render(); // Flush and flip glFlush(); SwapBuffers(hDC); } else { // If inactive, just rerender when we need to OpenGL_SetupView(fovmode); OpenGL_Render(); glFlush(); SwapBuffers(hDC); ValidateRect(hWnd, NULL); } return 0; } case WM_CHAR: { // Respond to keypresses switch (wParam) { // 'F' switches between preset fov modes case 'f': case 'F': { ++fovmode; if (fovmode == NUM_FOVMODES) fovmode = 0; switch (fovmode) { case FF_NORMAL: // Normal fov, full frame viewport { aspect = (float)GetSystemMetrics(SM_CXSCREEN) / GetSystemMetrics(SM_CYSCREEN); hfov = 90.0f; break; } case WS_WIDE: // Wide fov with a widescreen viewport (aspect ratio of 2.35, same as theatre) { aspect = 2.35f; hfov = 140.0f; break; } case FF_WIDE: // Wide fov with a full-frame viewport { aspect = (float)GetSystemMetrics(SM_CXSCREEN) / GetSystemMetrics(SM_CYSCREEN); hfov = 140.0f; break; } case 'd': { if (useLighting) { glEnable(GL_LIGHTING); } glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmb); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiff); glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpec); glEnable(GL_NORMALIZE); if (useFog){ glEnable(GL_FOG); } glFogfv(GL_FOG_COLOR, fogColor); glFogfv(GL_FOG_INDEX, fogIndex); glFogf(GL_FOG_MODE, GL_EXP); glFogf(GL_FOG_DENSITY, 0.5); glFogf(GL_FOG_START, 1.0); glFogf(GL_FOG_END, 3.0); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glShadeModel(GL_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); if (useLogo) { } else { glPolygonStipple((const GLubyte *) shadowPattern); } glClearColor(0.0, 0.0, 0.0, 1); glClearIndex(0); glClearDepth(1); } break; } // Escape key exits case 27: { DestroyWindow(hWnd); break; } } // Make sure window is redrawn InvalidateRect(hWnd, NULL, false); return 0; } case WM_LBUTTONDOWN: { if (active) { // Capture mouse and hide cursor SetCapture(hWnd); ShowCursor(false); // Save off mouse position GetCursorPos(&amp;mousepos); } return 0; } case WM_MOUSEMOVE: { // Move view angles if dragging left button if (active &amp;&amp; (wParam &amp; MK_LBUTTON)) { POINT pt; int deltax, deltay; bool wrap = false; // Get current mouse position GetCursorPos(&amp;pt); // Calculate deltas deltax = pt.x - mousepos.x; deltay = pt.y - mousepos.y; // Wrap mouse position if needed if (pt.x == GetSystemMetrics(SM_CXSCREEN) - 1) pt.x = 0, wrap = true; else if (pt.x == 0) pt.x = GetSystemMetrics(SM_CXSCREEN) - 1, wrap = true; if (pt.y == GetSystemMetrics(SM_CYSCREEN) - 1) pt.y = 0, wrap = true; else if (pt.y == 0) pt.y = GetSystemMetrics(SM_CYSCREEN) - 1, wrap = true; if (wrap) SetCursorPos(pt.x, pt.y); // Save off new mouse position mousepos = pt; // Change view angles accordingly cam_yaw -= (float)deltax * MOUSE_CAMERA_ANGLE_FACTOR; cam_pitch -= (float)deltay * MOUSE_CAMERA_ANGLE_FACTOR; // Wrap yaw and clamp pitch if (cam_yaw &gt; 360.0f) cam_yaw -= 360.0f; if (cam_yaw &lt; 0.0f) cam_yaw += 0.0f; if (cam_pitch &gt; 90.0f) cam_pitch = 90.0f; if (cam_pitch &lt; -90.0f) cam_pitch = -90.0f; InvalidateRect(hWnd, NULL, false); } return 0; } case WM_LBUTTONUP: { if (active) { // Release mouse capture and show cursor ReleaseCapture(); ShowCursor(true); } return 0; } case WM_DESTROY: { // Shut down OpenGL wglMakeCurrent(NULL, NULL); wglDeleteContext(hRC); ReleaseDC(hWnd, hDC); PostQuitMessage(0); return 0; } default: { return DefWindowProc(hWnd, message, wParam, lParam); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload