Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 2016ws
  • 2017ws
  • 2018ws
  • 2019ws
  • 2020ws
  • 2021ws
  • 2022ws
  • 2023ws
  • 2024ws
9 results

Target

Select target project
  • pgerwinski/hp
  • bwildenhain/hp
  • Daniel.Eisi/hp
  • aahrens/hp
4 results
Select Git revision
  • 2016ws
  • 2017ws
  • 2018ws
  • master
4 results
Show changes
Showing
with 0 additions and 1619 deletions
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <png.h>
#include "textured-spheres.h"
#ifndef __USE_POSIX
extern int fileno (FILE *stream);
#endif
static png_byte *load_png_file (char *filename, unsigned *w, unsigned *h)
{
FILE *f = fopen (filename, "rb");
if (!f)
return NULL;
/* is it a PNG file? */
png_byte buf[8];
if (fread (buf, 1, 8, f) != 8)
{
fclose (f);
return NULL;
}
if (!png_check_sig (buf, 8))
{
fclose (f);
return NULL;
}
png_struct *png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
NULL, NULL, NULL);
if (!png_ptr)
{
fclose (f);
return NULL;
}
png_info *info_ptr = png_create_info_struct (png_ptr);
if (!info_ptr)
{
fclose (f);
png_destroy_read_struct (&png_ptr, NULL, NULL);
return NULL;
}
if (setjmp (png_jmpbuf (png_ptr)))
{
fclose (f);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
png_init_io (png_ptr, f);
png_set_sig_bytes (png_ptr, 8);
png_read_info (png_ptr, info_ptr);
png_uint_32 width;
png_uint_32 height;
int bit_depth;
int color_type;
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, NULL, NULL, NULL);
/* tell libpng to strip 16 bit/color files down to 8 bits/color */
if (bit_depth == 16)
png_set_strip_16 (png_ptr);
/* expand paletted colors into true RGB triplets */
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand (png_ptr);
/* expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand (png_ptr);
/* expand paletted or RGB images with transparency to full alpha channels
so the data will be available as RGBA quartets. */
if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))
png_set_expand (png_ptr);
/* transform grayscale images into rgb */
if (color_type == PNG_COLOR_TYPE_GRAY
|| color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb (png_ptr);
if (color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha (png_ptr);
png_read_update_info (png_ptr, info_ptr);
png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth,
&color_type, NULL, NULL, NULL);
if (color_type != PNG_COLOR_TYPE_RGB
&& color_type != PNG_COLOR_TYPE_RGB_ALPHA)
{
fclose (f);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
png_uint_32 row_bytes = png_get_rowbytes (png_ptr, info_ptr);
if (row_bytes & 0x01)
row_bytes++;
png_byte *png_pixels = malloc (row_bytes * height * sizeof (png_byte));
if (png_pixels == NULL)
{
fclose (f);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
return NULL;
}
png_byte **row_pointers = malloc (height * sizeof (png_bytep));
if (row_pointers == NULL)
{
fclose (f);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
free (png_pixels);
png_pixels = NULL;
return NULL;
}
int i;
for (i = 0; i < height; i++)
row_pointers[i] = png_pixels + i * row_bytes;
png_read_image (png_ptr, row_pointers);
png_read_end (png_ptr, info_ptr);
png_destroy_read_struct (&png_ptr, &info_ptr, NULL);
fclose (f);
if (w)
*w = width;
if (h)
*h = height;
free (row_pointers);
return png_pixels;
}
void init_texture (char *image_filename, GLuint *texture)
{
unsigned image_width, image_height;
png_byte *image = load_png_file (image_filename, &image_width, &image_height);
if (!image)
{
fprintf (stderr, "textured-spheres.c: cannot open texture file \"%s\"",
image_filename);
exit (1);
}
glGenTextures (1, texture);
glBindTexture (GL_TEXTURE_2D, *texture);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
gluBuild2DMipmaps (GL_TEXTURE_2D, 3, image_width, image_height, GL_RGB, GL_UNSIGNED_BYTE, image);
}
void draw_textured_sphere (GLuint texture, GLdouble radius, GLint slices, GLint stacks)
{
static GLfloat white_color[] = { 1.0, 1.0, 1.0 };
glMaterialfv (GL_FRONT, GL_AMBIENT, white_color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, white_color);
glBindTexture (GL_TEXTURE_2D, texture);
glEnable (GL_TEXTURE_2D);
GLUquadric *sphere = gluNewQuadric ();
gluQuadricTexture (sphere, GL_TRUE);
gluSphere (sphere, radius, slices, stacks);
glDisable (GL_TEXTURE_2D);
}
#ifndef TEXTURED_SPHERES_H
#define TEXTURED_SPHERES_H
#include <GL/gl.h>
#include <GL/glu.h>
extern void init_texture (char *image_filename, GLuint *texture);
extern void draw_textured_sphere (GLuint texture, GLdouble radius, GLint slices, GLint stacks);
#endif /* TEXTURED_SPHERES_H */
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutMainLoop ();
glutTimerFunc (50, timer_handler, 0);
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glutSolidCube (0.75);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (-30.0, 0.5, 1.0, 0.0);
glutSolidCube (0.75);
glFlush ();
glutSwapBuffers ();
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glPushMatrix ();
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glPushMatrix ();
glRotatef (20.0 * t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glPopMatrix ();
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutDisplayFunc (draw);
glutTimerFunc (50, timer_handler, 0);
glutMainLoop ();
return 0;
}
File deleted
This diff is collapsed.
File deleted
% hp-uebung-20171113.pdf - Exercises on Low-Level Programming / Applied Computer Sciences
% Copyright (C) 2013, 2015, 2016, 2017 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Datum-Bibliothek, Primzahlen, rotierender Würfel
\documentclass[a4paper]{article}
\usepackage{pgscript}
\begin{document}
% \thispagestyle{empty}
\section*{Hardwarenahe Programmierung / Angewandte Informatik\\
Übungsaufgaben -- 13.\ November 2017}
\exercise{Datum-Bibliothek}
Schreiben Sie eine Bibliothek \file{dates.c} (mit Header-Datei \file{dates.h})
zur Behandlung von Datumsangaben.
Diese soll enthalten:
\begin{itemize}
\item
einen \lstinline{struct}-Datentyp \lstinline{date},
der eine Datumsangabe speichert,
\item
eine Funktion \lstinline{void date_print (date *d)}, die ein Datum ausgibt,
\item
eine Funktion \lstinline{int date_set (date *d, int day, int month, int year)},
die ein Datum auf einen gegebenen Tag setzt
und zurückgibt, ob es sich um ein gültiges Datum handelt (0 = nein, 1 = ja),
\item
eine Funktion \lstinline{void date_next (date *d)},
die ein Datum auf den nächsten Tag vorrückt.
\end{itemize}
\exercise{Fehlerhaftes Programm: Primzahlen}
\begin{minipage}[t]{5.5cm}
Das nebenstehende Primzahlsuchprogramm (Datei: \gitfile{hp}{20171113}{aufgabe-2.c})
soll Zahlen ausgeben, die genau zwei Teiler haben, ist aber fehlerhaft.
\smallskip
Korrigieren Sie das Programm derart, daß ein Programm entsteht,
welches alle Primzahlen kleiner 100 ausgibt.% \points 5
\end{minipage}\hfill
\begin{minipage}[t]{9cm}
\vspace*{-0.5cm}
\begin{lstlisting}[gobble=6]
#include <stdio.h>
int main (void)
{
int n, i, divisors;
for (n = 0; n < 100; n++)
divisors = 0;
for (i = 0; i < n; i++)
if (n % i == 0)
divisors++;
if (divisors = 2)
printf ("%d ist eine Primzahl.\n", n);
return 0;
}
\end{lstlisting}
\end{minipage}
\exercise{Fehlerhaftes Programm: Rotierender Würfel}
Das auf der nächsten Seite abgedruckte OpenGL-Programm
(Datei: \gitfile{hp}{20171113}{aufgabe-3.c}) soll einen sich
gleichmäßig drehenden Würfel darstellen, ist jedoch fehlerhaft.
(Die Datei \gitfile{hp}{20171113}{opengl-magic.h} sowie die zugehörige C-Datei
\gitfile{hp}{20171113}{opengl-magic.c} sind die aus der Vorlesung bekannten Beispiel-Dateien,
die Sie zusammen mit diesen Übungsaufgaben herunterladen können.)
\begin{itemize}
\item[(a)]
Warum sieht man lediglich ein leeres Fenster?
Welchen Befehl muß man ergänzen, um diesen Fehler zu beheben?
% \points{4}
\end{itemize}
Nach der Fehlerbehebung in Aufgabenteil (a)
zeigt das Programm einen sich drehenden Würfel.
% (Sie können sich diesen während der Klausur jederzeit vorführen lassen.)
\begin{itemize}
\item[(b)]
Erklären Sie das Drehverhalten des Würfels. % \points{4}
\item[(c)]
Welche Befehle muß man ergänzen,
um eine gleichförmige Drehung zu erhalten? % \points{4}
\end{itemize}
\filbreak
\begin{lstlisting}
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include "opengl-magic.h"
float t = 0.0;
void draw (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
set_material_color (1.0, 0.7, 0.0);
glRotatef (t, 0.5, 1.0, 0.0);
glutSolidCube (0.5);
glFlush ();
glutSwapBuffers ();
}
void timer_handler (int value)
{
t += 0.05;
glutPostRedisplay ();
glutTimerFunc (50, timer_handler, 0);
}
int main (int argc, char **argv)
{
init_opengl (&argc, argv, "Cube");
glutMainLoop ();
glutTimerFunc (50, timer_handler, 0);
return 0;
}
\end{lstlisting}
\end{document}
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
#include <stdio.h>
#define VIER 4
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 4;
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 2 + 2
int main (void)
{
printf ("%d\n", VIER);
return 0;
}
#include <stdio.h>
#define VIER 2 + 2
int main (void)
{
printf ("3 * 4 = %d\n", 3 * VIER);
return 0;
}
#include <stdio.h>
#define VIER (2 + 2)
int main (void)
{
printf ("3 * 4 = %d\n", 3 * VIER);
return 0;
}
#include <stdio.h>
int main (int argc, char **argv)
{
printf ("argc = %d\n", argc);
for (int i = 0; i < 4; i++)
printf ("argv[%d] = %s\n", i, argv[i]);
return 0;
}
#if defined(__APPLE__) || defined(MACOSX)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#endif
#include "opengl-magic.h"
void init_opengl (int *argcp, char **argv, char *window_name)
{
glutInit (argcp, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (1024, 768);
glutCreateWindow (window_name);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (20.0, -1.33333, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
static GLfloat light0_position[] = { 1.0, 0.0, 1.0, 0.0 };
glLightfv (GL_LIGHT0, GL_POSITION, light0_position);
}
void set_material_color (float r, float g, float b)
{
GLfloat color[] = { r, g, b };
glMaterialfv (GL_FRONT, GL_AMBIENT, color);
glMaterialfv (GL_FRONT, GL_DIFFUSE, color);
}
#if defined(__APPLE__) || defined(MACOSX)
void glutSolidCylinder (double radius, double height, int slices, int stacks)
{
GLUquadricObj *q = gluNewQuadric ();
gluCylinder (q, radius, radius, height, slices, stacks);
gluDeleteQuadric (q);
}
#endif